title: How to schedule local notifications with flutter
body: <p>I'm unable to show a daily local notifications based on time picked by user. </p>
  
  <p>To see if I forgot any permissions, I tried implementing a button to show a local notification straight away and that worked.</p>
  
  <p>if a notification is scheduled, this code make sure it shows when the page loads</p>
  
  <pre><code>class _LocalNotificationWidgetState extends State&lt;LocalNotificationWidget&gt; {
    final notifications = FlutterLocalNotificationsPlugin();
    Time timePickedtime;
    TimeOfDay _time = TimeOfDay.now();
    TimeOfDay picked;
    var timeText;
    bool showReminder;
    String remindTime;
  
   @override
    void initState() {
      getReminderTime().then((result) {
        setState(() {
          result != null ? timeText = result : timeText = '00:00';
        });
      });
      getReminder().then((result) {
        setState(() {
          showReminder = result;
        });
      });
      super.initState();
    }
  </code></pre>
  
  <p>building the timepicker widget</p>
  
  <pre><code>   Widget _buildTimePicker() {
      return GestureDetector(
        onTap: () async {
          await _showDailyAtTime(context);
        },
        child: Container(
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(5.0)),
              color: Colors.white),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: &lt;Widget&gt;[
              Text(
                timeText != null ? timeText.toString() : '00:00',
                style: TextStyle(fontSize: 50.0, fontWeight: FontWeight.w200),
              ),
              Switch(
                value: showReminder == null ? false : showReminder,
                onChanged: (bool value) {
                  setState(() {
                    showReminder = value;
                    setReminder(value);
                  });
                },
              ),
            ],
          ),
        ),
      );
    }
  </code></pre>
  
  <p>the scheduling method</p>
  
  <pre><code>
  Future&lt;Null&gt; _showDailyAtTime(BuildContext context) async {
      picked = await showTimePicker(context: context, initialTime: _time);
      if (picked != null &amp;&amp; picked != _time) {
        setState(() {
          _time = picked;
        });
      }
      if (picked != null) {
        timePickedtime = Time(picked.hour, picked.minute, 0);
      }
  
      var androidPlatformChannelSpecifics = AndroidNotificationDetails(
          'repeatDailyAtTime channel id',
          'repeatDailyAtTime channel name',
          'repeatDailyAtTime description');
      var iOSPlatformChannelSpecifics = IOSNotificationDetails();
      var platformChannelSpecifics = NotificationDetails(
          androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
      setState(() {
        timeText =
            '${_toTwoDigitString(picked.hour)}:${_toTwoDigitString(picked.minute)}';
        setReminderTime(timeText);
      });
  
      if (showReminder) {
        await notifications.showDailyAtTime(
            0,
            'Reminder',
            'Have you used this app today? Daily notification shown at approximately ${_toTwoDigitString(picked.hour)}:${_toTwoDigitString(picked.minute)}:',
            timePickedtime,
            platformChannelSpecifics);
      }
    }
  </code></pre>
  
  <p>storing schedule on device</p>
  
  <pre><code>
  
    Future&lt;bool&gt; getReminder() async {
      final SharedPreferences prefs = await SharedPreferences.getInstance();
  
      return prefs.getBool('showReminder');
    }
  
    Future&lt;bool&gt; setReminder(bool value) async {
      final SharedPreferences prefs = await SharedPreferences.getInstance();
  
      return prefs.setBool('showReminder', value);
    }
  
    Future&lt;bool&gt; setReminderTime(String value) async {
      final SharedPreferences prefs = await SharedPreferences.getInstance();
  
      return prefs.setString('timeText', value);
    }
  
    Future&lt;String&gt; getReminderTime() async {
      final SharedPreferences prefs = await SharedPreferences.getInstance();
  
      return prefs.getString('timeText');
    }
  </code></pre>