google addin
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../services/app_settings.dart';
|
||||
import '../utils/translations.dart';
|
||||
import '../services/notification_service.dart';
|
||||
@@ -12,6 +13,8 @@ import 'camera_settings_screen.dart';
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
static const _privacyPolicyUrl = 'https://sdkovinarmuta.si/privacy-and-policy/';
|
||||
|
||||
static final Future<PackageInfo> _packageInfo = PackageInfo.fromPlatform();
|
||||
|
||||
@override
|
||||
@@ -119,6 +122,17 @@ class SettingsScreen extends StatelessWidget {
|
||||
),
|
||||
]),
|
||||
|
||||
SectionHeader(t('About')),
|
||||
GroupCard(children: [
|
||||
SettingsTile(
|
||||
title: t('Privacy policy'),
|
||||
onTap: () => launchUrl(
|
||||
Uri.parse(_privacyPolicyUrl),
|
||||
mode: LaunchMode.externalApplication,
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
||||
const SizedBox(height: 28),
|
||||
FutureBuilder<PackageInfo>(
|
||||
future: _packageInfo,
|
||||
@@ -233,23 +247,27 @@ class SettingsScreen extends StatelessWidget {
|
||||
final s = AppSettings.instance;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
// 7 options exceed the default 9/16 height cap on smaller phones
|
||||
isScrollControlled: true,
|
||||
builder: (sheet) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_SheetTitle(s.t('Remind me')),
|
||||
for (final h in AppSettings.reminderHourOptions)
|
||||
SheetOption(
|
||||
label: _hoursBefore(h),
|
||||
selected: h == s.reminderHours,
|
||||
selectedColor: s.bulletColor,
|
||||
onTap: () {
|
||||
s.setReminderHours(h).then((_) => _reschedule());
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_SheetTitle(s.t('Remind me')),
|
||||
for (final h in AppSettings.reminderHourOptions)
|
||||
SheetOption(
|
||||
label: _hoursBefore(h),
|
||||
selected: h == s.reminderHours,
|
||||
selectedColor: s.bulletColor,
|
||||
onTap: () {
|
||||
s.setReminderHours(h).then((_) => _reschedule());
|
||||
Navigator.pop(sheet);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -63,9 +63,34 @@ class NotificationService {
|
||||
AndroidFlutterLocalNotificationsPlugin>();
|
||||
await androidPlugin?.createNotificationChannel(_channel);
|
||||
await requestPermissions();
|
||||
await _requestExactAlarmsOnce();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
// Android 12+ needs "Alarms & reminders" access for on-time delivery
|
||||
// (denied by default on Android 14+). Ask once; without it we fall back
|
||||
// to inexact alarms, which Android may delay by an hour or more.
|
||||
Future<void> _requestExactAlarmsOnce() async {
|
||||
final android = _plugin.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin>();
|
||||
if (android == null) return;
|
||||
if (await android.canScheduleExactNotifications() ?? true) return;
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.getBool('exactAlarmAsked') ?? false) return;
|
||||
await prefs.setBool('exactAlarmAsked', true);
|
||||
await android.requestExactAlarmsPermission();
|
||||
}
|
||||
|
||||
Future<AndroidScheduleMode> _scheduleMode() async {
|
||||
final android = _plugin.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin>();
|
||||
final canExact = await android?.canScheduleExactNotifications() ?? true;
|
||||
return canExact
|
||||
? AndroidScheduleMode.exactAllowWhileIdle
|
||||
: AndroidScheduleMode.inexactAllowWhileIdle;
|
||||
}
|
||||
|
||||
/// Fetches the calendar and reschedules all reminders. Call on app start
|
||||
/// and whenever notification settings change.
|
||||
Future<void> rescheduleFromCalendar() async {
|
||||
@@ -118,6 +143,7 @@ class NotificationService {
|
||||
final notifyTekma = prefs.getBool('notifyTekma') ?? true;
|
||||
final language = prefs.getString('language') ?? 'Slovenian';
|
||||
final now = DateTime.now();
|
||||
final mode = await _scheduleMode();
|
||||
|
||||
await _plugin.cancelAll();
|
||||
|
||||
@@ -143,6 +169,7 @@ class NotificationService {
|
||||
title: event.summary ?? 'Event',
|
||||
body: _startsIn(hours, language),
|
||||
scheduledDate: notifyAt,
|
||||
mode: mode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -167,6 +194,7 @@ class NotificationService {
|
||||
required String title,
|
||||
required String body,
|
||||
required DateTime scheduledDate,
|
||||
required AndroidScheduleMode mode,
|
||||
}) async {
|
||||
final tzDate = tz.TZDateTime.from(scheduledDate, tz.local);
|
||||
await _plugin.zonedSchedule(
|
||||
@@ -175,8 +203,7 @@ class NotificationService {
|
||||
body,
|
||||
tzDate,
|
||||
_notifDetails,
|
||||
// Inexact: avoids the SCHEDULE_EXACT_ALARM permission (Play policy).
|
||||
androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle,
|
||||
androidScheduleMode: mode,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime,
|
||||
);
|
||||
|
||||
@@ -192,6 +192,16 @@ class AppTranslations {
|
||||
},
|
||||
|
||||
// Camera settings
|
||||
'About': {
|
||||
'English': 'About',
|
||||
'Slovenian': 'O aplikaciji',
|
||||
'German': 'Über',
|
||||
},
|
||||
'Privacy policy': {
|
||||
'English': 'Privacy policy',
|
||||
'Slovenian': 'Politika zasebnosti',
|
||||
'German': 'Datenschutzerklärung',
|
||||
},
|
||||
'Camera Settings': {
|
||||
'English': 'Camera Settings',
|
||||
'Slovenian': 'Nastavitve kamere',
|
||||
|
||||
Reference in New Issue
Block a user