Add app icon and local notifications

Also add android version
This commit is contained in:
Ricardo Markiewicz
2019-07-09 16:13:04 -03:00
parent 99de6c4ef9
commit 776648b470
35 changed files with 365 additions and 23 deletions
+67
View File
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:rect_getter/rect_getter.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import '../login_state.dart';
import '../utils.dart';
@@ -16,6 +17,7 @@ class HomePage extends StatefulWidget {
}
class _HomePageState extends State<HomePage> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
var globalKey = RectGetter.createGlobalKey();
Rect buttonRect;
@@ -32,6 +34,8 @@ class _HomePageState extends State<HomePage> {
initialPage: currentPage,
viewportFraction: 0.4,
);
setupNotificationPlugin();
}
Widget _bottomAction(IconData icon, Function callback) {
@@ -209,4 +213,67 @@ class _HomePageState extends State<HomePage> {
),
);
}
void setupNotificationPlugin() {
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid = new AndroidInitializationSettings('app_icon');
var initializationSettingsIOS = new IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification,
);
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid,
initializationSettingsIOS,
);
flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onSelectNotification: onSelectNotification,
).then((init) {
setupNotification();
});
}
Future onSelectNotification(String payload) async {
if (payload != null) {
debugPrint('notification payload: ' + payload);
}
await Navigator.push(
context,
new MaterialPageRoute(builder: (context) => HomePage()),
);
}
Future onDidReceiveLocalNotification(
int id, String title, String body, String payload) async {
// display a dialog with the notification details, tap ok to go to another page
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text("Don't forget to add your expenses"),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
));
}
void setupNotification() async {
var time = new Time(16, 11, 0);
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'daily-notifications',
'Daily Notifications',
'Daily Notifications');
var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showDailyAtTime(0, 'Spend-o-meter',
"Don't forget to add your expenses", time, platformChannelSpecifics);
}
}