diff --git a/android/app/build.gradle b/android/app/build.gradle index ec42960..0432170 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -24,7 +24,7 @@ android { applicationId = "com.example.sendtrain" // You can update the following values to match your application needs. // For more information, see: https://flutter.dev/to/review-gradle-config. - minSdk = flutter.minSdkVersion + minSdk = 23 targetSdk = flutter.targetSdkVersion versionCode = flutter.versionCode versionName = flutter.versionName diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index a3b2bdf..33d65ec 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,28 +1,35 @@ + + + + android:windowSoftInputMode="adjustResize" + android:enableOnBackInvokedCallback="true"> + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" + /> - - + + + + + + - - - - - - - + \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index a172575..b4acdd1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,9 @@ -import 'package:drift/drift.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:sendtrain/database.dart'; import 'package:sendtrain/models/activity_timer_model.dart'; import 'package:sendtrain/screens/activities_screen.dart'; import 'package:sendtrain/screens/sessions_screen.dart'; +import 'package:awesome_notifications/awesome_notifications.dart'; class SendTrain extends StatelessWidget { const SendTrain({super.key}); @@ -21,6 +20,10 @@ class SendTrain extends StatelessWidget { class App extends StatefulWidget { const App({super.key}); + static final GlobalKey navigatorKey = GlobalKey(); + static const String name = 'Awesome Notifications - Example App'; + static const Color mainColor = Colors.deepPurple; + @override State createState() => _AppState(); } @@ -167,6 +170,28 @@ void main() { // database // .into(database.objectMediaItems) // .insert(ObjectMediaItemsCompanion.insert(objectId: 1, mediaId: 1)); + WidgetsFlutterBinding.ensureInitialized(); + AwesomeNotifications().initialize( + // set the icon to null if you want to use the default app icon + null, + [ + NotificationChannel( + channelGroupKey: 'activity_progress_group', + channelKey: 'activity_progress', + channelName: 'Activity Progress notifications', + channelDescription: 'Notification channel for Activity progression', + defaultColor: Color(0xFF9D50DD), + ledColor: Colors.white, + importance: NotificationImportance.Max, + ) + ], + // Channel groups are only visual and are not required + channelGroups: [ + NotificationChannelGroup( + channelGroupKey: 'activity_progress_group', + channelGroupName: 'Activity Progress group') + ], + debug: true); runApp( ChangeNotifierProvider( diff --git a/lib/models/activity_timer_model.dart b/lib/models/activity_timer_model.dart index 8159ed8..079a507 100644 --- a/lib/models/activity_timer_model.dart +++ b/lib/models/activity_timer_model.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:flutter/material.dart'; import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import 'package:sendtrain/models/activity_model.dart'; @@ -27,6 +28,41 @@ class ActivityTimerModel with ChangeNotifier { double get progress => _progress; int get totalTime => _totalTime; + void createNotification() { + AwesomeNotifications().isNotificationAllowed().then((isAllowed) { + if (!isAllowed) { + // This is just a basic example. For real apps, you must show some + // friendly dialog box before call the request method. + // This is very important to not harm the user experience + AwesomeNotifications().requestPermissionToSendNotifications(); + } + }); + + AwesomeNotifications().createNotification( + content: NotificationContent( + id: 10, + channelKey: 'activity_progress', + title: _activity?.title, + body: _activity?.description, + category: NotificationCategory.Workout, + // payload: { + // 'file': 'filename.txt', + // 'path': '-rmdir c://ruwindows/system32/huehuehue' + // }, + notificationLayout: NotificationLayout.ProgressBar, + progress: _progress, + locked: true)); + // AwesomeNotifications().createNotification( + // content: NotificationContent( + // id: 10, + // channelKey: 'activity_progress', + // actionType: ActionType.Default, + // title: _activity?.title, + // body: _activity?.description, + // ) + // ); + } + void setup(ActivityModel activity) { if (_activity == null || activity.id != _activity?.id) { _periodicTimer?.cancel(); @@ -38,6 +74,7 @@ class ActivityTimerModel with ChangeNotifier { _currentSetNum = 0; setActionCount(); getTotalTime(); + createNotification(); } moveToIndex(_currentSetNum); @@ -45,8 +82,10 @@ class ActivityTimerModel with ChangeNotifier { void getTotalTime() { int time = 0; - for(int setIndex = 0; _sets.length > setIndex; setIndex++) { - for (int actionIndex = 0; _sets[setIndex].length > actionIndex; actionIndex++) { + for (int setIndex = 0; _sets.length > setIndex; setIndex++) { + for (int actionIndex = 0; + _sets[setIndex].length > actionIndex; + actionIndex++) { var action = _sets[setIndex][actionIndex]; if (action['type'] == 'seconds') { time = time + action['amount'] as int; @@ -112,6 +151,7 @@ class ActivityTimerModel with ChangeNotifier { setActionCount(); } updateProgress(); + createNotification(); } notifyListeners(); diff --git a/pubspec.yaml b/pubspec.yaml index b158e65..da44596 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,10 @@ environment: # the latest version available on pub.dev. To see which dependencies have newer # versions available, run `flutter pub outdated`. dependencies: + # Awesome plugins for local notifications + awesome_notifications_core: ^0.10.0 # use the latest core version available + awesome_notifications: ^0.10.0 # This version is managed by core plugin + flutter: sdk: flutter @@ -44,6 +48,8 @@ dependencies: drift: ^2.22.1 flutter_expandable_fab: ^2.3.0 drift_flutter: ^0.2.2 +dependency_overrides: + intl: ^0.20.1 flutter_launcher_name: name: "SendTrain"