Scheduled notification datetime

226 views
Skip to first unread message

Albe

unread,
Oct 20, 2020, 4:24:22 PM10/20/20
to Flutter Development (flutter-dev)
Hi,

I'm looking to integrate Flutter's plugin date_time_picker with local notification.

So when I select a date&time I also schedule a notification.

Here's my code..could you help me? Now I don't have any error but code is not working.

Code:

Future scheuleAtParticularTime(DateTime timee) async {

    var time = DateTime(timee.day, timee.month, timee.year, timee.hour,

        timee.minute, timee.second);


    var scheduledNotificationDateTime =

        new DateTime.now().add(new Duration(seconds: 1));

    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(

        'your other channel id',

        'your other channel name',

        'your other channel description');

    var iOSPlatformChannelSpecifics = new IOSNotificationDetails();

    NotificationDetails platformChannelSpecifics = new NotificationDetails(

        android: androidPlatformChannelSpecifics,

        iOS: iOSPlatformChannelSpecifics);

    // tz.initializeTimeZones();

    // tz.setLocalLocation(tz.getLocation('Italy'));

    await fltrNotification.schedule(1, 'scheduled title', 'scheduled body',

        scheduledNotificationDateTime, platformChannelSpecifics);

  }


  @override

  Widget build(BuildContext context) {

    return Scaffold(

      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,

          children: [

            FlatButton(

              onPressed: () {

                DatePicker.showDateTimePicker(context, showTitleActions: true,

                    onChanged: (date) {

                  print('change $date');

                }, onConfirm: (date) {

                  print('confirm $date');

                  scheuleAtParticularTime(DateTime.fromMillisecondsSinceEpoch(

                      date.millisecondsSinceEpoch));

                }, currentTime: DateTime.now(), locale: LocaleType.it);

              },

              child: Text(

                'Select time for notification arrival',

                style:

                    TextStyle(color: Colors.black, fontWeight: FontWeight.w900),

              ),

            ),

          ],

        ),

      ),

    );

  }


Thanks!

Suzuki Tomohiro

unread,
Oct 20, 2020, 4:31:37 PM10/20/20
to Flutter Development (flutter-dev)
> code is not working

What do you observe? (Why do you say the code is not working?)


--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/5eed40c6-d1b1-4a25-a7b3-f014470811efn%40googlegroups.com.

Albe

unread,
Oct 20, 2020, 4:35:09 PM10/20/20
to Flutter Development (flutter-dev)
Because I got the notification about 3-5 seconds after the button pressed (and not at the scheduled time)

Suzuki Tomohiro

unread,
Oct 20, 2020, 5:02:48 PM10/20/20
to Albe, Flutter Development (flutter-dev)
The first arguments for DateTime are year, month, and day in this order. You pass “day, month, year”:

var time = DateTime(timee.day, timee.month, timee.year, timee.hour,

        timee.minute, timee.second);



Albe

unread,
Oct 20, 2020, 5:17:29 PM10/20/20
to Flutter Development (flutter-dev)
Ok, I've changed it in:

var time = DateTime(timee.year, timee.month, timee.day, timee.hour,
timee.minute, timee.second);

but I got the same result

Andy Greenshaw

unread,
Oct 20, 2020, 5:19:42 PM10/20/20
to Albe, Flutter Development (flutter-dev)
I think 1 second is too small. Try with 10.

    ‘var scheduledNotificationDateTime = DateTime.now().add(new Duration(seconds: 1));’



From: flutt...@googlegroups.com <flutt...@googlegroups.com> on behalf of Albe <albe...@gmail.com>
Sent: Tuesday, October 20, 2020 9:35:09 PM
To: Flutter Development (flutter-dev) <flutt...@googlegroups.com>
Subject: Re: Scheduled notification datetime
 

Suzuki Tomohiro

unread,
Oct 20, 2020, 5:23:13 PM10/20/20
to Andy Greenshaw, Albe, Flutter Development (flutter-dev)
Add debug output for scheduledNotificationDateTime.

Albe

unread,
Oct 20, 2020, 5:29:12 PM10/20/20
to Flutter Development (flutter-dev)
I don't have any error in the console, just this when I scroll the data & date picker:

I/flutter ( 6214): change 2020-10-20 23:28:00.000
I/flutter ( 6214): confirm 2020-10-20 23:28:00.000

Suzuki Tomohiro

unread,
Oct 21, 2020, 9:44:48 AM10/21/20
to Flutter Development (flutter-dev)
If I understand correctly, your problem is irrelevant to user picking a time. Scheduled notification is not triggering at scheduled time. Can you demonstrate this problem without a time picking?

And what about Andy’s suggestion on 1 second too small?

On Wed, Oct 21, 2020 at 01:29 Albe <albe...@gmail.com> wrote:
Expected, picked from the plugin date time

Il Mar 20 Ott 2020, 23:40 Suzuki Tomohiro <suz...@gmail.com> ha scritto:
Are these dates expected or unexpected?

Reply all
Reply to author
Forward
0 new messages