1

I'm trying to use zonedshedule in Flutter local notifications. But exception is returning as null 'timeZone' was called on null.

Rahul Kavati
  • 1,649
  • 1
  • 6
  • 11

1 Answers1

6

Import packages from timezone package from pub dev

Now, add those to your dart file as referring to tz:

import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest.dart' as tz;

Now, make initialize the timeZones:

void main() {
  tz.initializeTimeZones();
  var locations = tz.timeZoneDatabase.locations;
}

Now, you can convert DateTime to TZDateTime for zonedShedule:

DateTime time;
tz.TZDateTime selectedDate;

selectedDate =  tz.TZDateTime.from(time, tz.local);
Rahul Kavati
  • 1,649
  • 1
  • 6
  • 11