Closed minh98 closed 5 years ago
This is actually working as expected. Datetime.now () gets evaluated before it gets passed to the Android/iOS via platform channels. You'll need to look at implementing what you need for your app in a different way e.g. look at using platform channels and write custom code yourself
When notifi showing it has time incorrect (not equal when it be showing). I am installed app in 23/2/2019 but next day is 24/2/2019 time of notifi still is 23/2/2019. I think it set constant time for any notifi 🤔. I was call datetime.now() but not correct maybe. My code
` @override void initState() { super.initState(); storageHelper = StorageHelper(); dataFuture = getLichFromFile(); nameFuture = getNameFromProfile(); classFuture = getClassFromProfile(); msvFuture = getMSVFromProfile(); firstInitNotification(); }
firstInitNotification() async { String init = await storageHelper.readFile(Path.initNotifi); if (init != 'done') { storageHelper.writeFile('done', Path.initNotifi).then((file) { initNotification(); }); } }
initNotification() async { 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('@mipmap/ic_logo'); var initializationSettingsIOS = new IOSInitializationSettings(); var initializationSettings = new InitializationSettings( initializationSettingsAndroid, initializationSettingsIOS); await flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onSelectNotification); activeShowDaily(); }
activeShowDaily() async { var time = new Time(19, 30, 0); var androidPlatformChannelSpecifics = new AndroidNotificationDetails( 'repeatDailyAtTime channel id', 'repeatDailyAtTime channel name', 'repeatDailyAtTime description', style: AndroidNotificationStyle.BigText, autoCancel: false, styleInformation: BigTextStyleInformation( await getLichNgayMai(), ), icon: '@mipmap/ic_logo', largeIcon: '@mipmap/ic_logo', ); var iOSPlatformChannelSpecifics = new IOSNotificationDetails(); var platformChannelSpecifics = new NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.showDailyAtTime( 0, 'Lịch cá nhân - Ngà y ${DateTime.now().day}-${DateTime.now().month}-${DateTime.now().year}', await getLichNgayMaiNormal(), time, platformChannelSpecifics); // // var scheduledNotificationDateTime = // new DateTime.now().add(new Duration(seconds: 5)); // var androidPlatformChannelSpecifics = new AndroidNotificationDetails( // 'your other channel id', // 'your other channel name', // 'your other channel description', // style: AndroidNotificationStyle.BigText, // autoCancel: false, // styleInformation: BigTextStyleInformation(await getLichNgayMai(),), // icon: '@mipmap/ic_logo' // ); // var iOSPlatformChannelSpecifics = new IOSNotificationDetails(); // NotificationDetails platformChannelSpecifics = new NotificationDetails( // androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); // await flutterLocalNotificationsPlugin.schedule( // 0, // 'Lịch cá nhân', // await getLichNgayMaiNormal(), // scheduledNotificationDateTime, // platformChannelSpecifics); } `