The flutter app does not push any local notification

31 views Asked by At

I made a code that pushed a notification after 1 minute like below.

  FlutterLocalNotificationsPlugin  _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

  void initState(){
    super.initState();
    _init();
  }
  Future<void> configureTime() async{
    tz.initializeTimeZones();
    final String? tzName = await FlutterNativeTimezone.getLocalTimezone();
    setLocalLocation(getLocation(tzName!));
  }
  Future<void> initNotification() async{
    const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher');
    const InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid,);
    await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
  }
  Future<void> _MsgSetting({
    required int hour, required message, required int minutes
  }) async{
    final TZDateTime now = TZDateTime.now(local);
    TZDateTime scheduledDate = TZDateTime(
        local,
        now.year,
        now.month,
        now.day,
        hour,
        minutes,
    );
    await _flutterLocalNotificationsPlugin.zonedSchedule(
        0,
        'Push Note Test',
        message, scheduledDate, NotificationDetails(
      android: AndroidNotificationDetails(
          'Channel ID',
          'Channel Name',
          importance: Importance.max,
          priority: Priority.high,
          ongoing: true,
          styleInformation: BigTextStyleInformation(message),
          icon: '@mipmap/ic_launcher'
      ),
    ),
        uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
        matchDateTimeComponents: DateTimeComponents.time
    );
  }
  Future<void> _init() async{
    await configureTime();
    await initNotification();
  }

...


return ElevatedButton(onPressed: () async{
                  print('Push Not button pressed');
                  final TZDateTime now = TZDateTime.now(local);
                  print(local);
                  print('Current Time');
                  print(now);

                  await _MsgSetting(hour:now.hour,minutes: now.minute+1,
                      message: 'Push Please');
                }, child: Text('Push Not Test'))

And I pushed the button several times, but no error message and no notification appeared.

I am very first with this plugin so I cannot even guess what is wrong.

Please help me and thank you very much.

0

There are 0 answers