diff --git a/android/app/src/main/res/drawable/app_icon.png b/android/app/src/main/res/drawable/app_icon.png new file mode 100644 index 0000000..db77bb4 Binary files /dev/null and b/android/app/src/main/res/drawable/app_icon.png differ diff --git a/lib/AppDrawer.dart b/lib/AppDrawer.dart index 352e08b..3636bf8 100644 --- a/lib/AppDrawer.dart +++ b/lib/AppDrawer.dart @@ -25,6 +25,13 @@ class AppDrawer extends StatelessWidget { Navigator.pushNamed(context, "/years"); } ), + ListTile( + title: Text("Notifications"), + onTap: () { + Navigator.pop(context); + Navigator.pushNamed(context, "/notifications"); + } + ), ListTile( title: Text("Practice Months"), onTap: () { diff --git a/lib/main.dart b/lib/main.dart index 3e124ef..63c2892 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,12 +1,85 @@ import 'package:flutter/material.dart'; +import 'package:ohthatsa/pages/NotificationsPage.dart'; import 'package:ohthatsa/pages/YearsPage.dart'; import 'package:ohthatsa/pages/practice/PracticeSetup.dart'; import 'package:ohthatsa/pages/practice/PracticeSetupPage.dart'; import 'package:ohthatsa/pages/practice/PracticePage.dart'; import 'package:ohthatsa/pages/MonthValuesPage.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:rxdart/subjects.dart'; +import 'package:flutter/services.dart'; + +final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + +final BehaviorSubject didReceiveLocalNotificationSubject = + BehaviorSubject(); + +final BehaviorSubject selectNotificationSubject = + BehaviorSubject(); + +const MethodChannel platform = + MethodChannel('dexterx.dev/flutter_local_notifications_example'); + +class ReceivedNotification { + ReceivedNotification({ + @required this.id, + @required this.title, + @required this.body, + @required this.payload, + }); + + final int id; + final String title; + final String body; + final String payload; +} + + +Future main() async { + + // Notification stuff + WidgetsFlutterBinding.ensureInitialized(); + + final NotificationAppLaunchDetails notificationAppLaunchDetails = + await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); + + const AndroidInitializationSettings initializationSettingsAndroid = + AndroidInitializationSettings('app_icon'); + + final IOSInitializationSettings initializationSettingsIOS = + IOSInitializationSettings( + requestAlertPermission: false, + requestBadgePermission: false, + requestSoundPermission: false, + onDidReceiveLocalNotification: + (int id, String title, String body, String payload) async { + didReceiveLocalNotificationSubject.add(ReceivedNotification( + id: id, title: title, body: body, payload: payload)); + }); + const MacOSInitializationSettings initializationSettingsMacOS = + MacOSInitializationSettings( + requestAlertPermission: false, + requestBadgePermission: false, + requestSoundPermission: false + ); + final InitializationSettings initializationSettings = InitializationSettings( + android: initializationSettingsAndroid, + iOS: initializationSettingsIOS, + macOS: initializationSettingsMacOS + ); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + onSelectNotification: (String payload) async { + if (payload != null) { + debugPrint('notification payload: $payload'); + } + selectNotificationSubject.add(payload); + } + ); + // end of notification stuff the fuck -void main() { runApp(OhThatsA()); } @@ -36,6 +109,9 @@ class RouteGenerator { case "/practice/practice": { return MaterialPageRoute(builder: (context) => PracticePage(settings.arguments)); } + case "/notifications": { + return MaterialPageRoute(builder: (context) => NotificationsPage()); + } default: { return MaterialPageRoute(builder: (context) => YearsPage()); } diff --git a/lib/pages/NotificationsPage.dart b/lib/pages/NotificationsPage.dart new file mode 100644 index 0000000..c941394 --- /dev/null +++ b/lib/pages/NotificationsPage.dart @@ -0,0 +1,48 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:ohthatsa/AppDrawer.dart'; +import 'package:ohthatsa/main.dart'; + +class NotificationsPage extends StatefulWidget { + @override + _NotificationPageState createState() => _NotificationPageState(); +} + +class _NotificationPageState extends State { + @override + Widget build(BuildContext context){ + return Scaffold( + drawer: AppDrawer(), + appBar: AppBar( + title: Text("Notifications") + ), + body: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + FlatButton( + child: Text("Notify!"), + color: Colors.blue, + textColor: Colors.white, + onPressed: _notify + ) + ], + ) + ); + } + + Future _notify() async { + const AndroidNotificationDetails androidPlatformChannelSpecifics = + AndroidNotificationDetails("test", "test", "test", ticker: 'ticker'); + const NotificationDetails platformChannelSpecifics = + NotificationDetails(android: androidPlatformChannelSpecifics); + await flutterLocalNotificationsPlugin.show( + 0, + 'Title!', + 'and the body...', + platformChannelSpecifics, + payload: "test item?" + ); + + } +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 2a21c50..8f5519e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,11 @@ dependencies: sqflite: ^1.3.0 intl: ^0.16.1 + # Notification libs + rxdart: ^0.24.0 + flutter_local_notifications: ^3.0.1+5 + + # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.