123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- import 'package:flutter/material.dart';
- import 'package:flutter_habit/common/I18N.dart';
- import 'package:flutter_habit/common/components/PopMenus.dart';
- import 'package:flutter_habit/provider/ConfigProvider.dart';
- import 'package:flutter_habit/provider/DataProvider.dart';
- import 'package:flutter_habit/provider/NotificationProvider.dart';
- import 'package:flutter_habit/common/utils/ConvertUtils.dart';
- import 'package:provider/provider.dart';
- class SignTimeSetPage extends StatefulWidget {
- @override
- _SignTimeSetPageState createState() => _SignTimeSetPageState();
- }
- class _SignTimeSetPageState extends State<SignTimeSetPage> {
- @override
- Widget build(BuildContext context) {
- ConfigProvider configProvider =
- Provider.of<ConfigProvider>(context, listen: true);
- ConfigProvider configProviderUnListen =
- Provider.of<ConfigProvider>(context, listen: false);
- DataProvider dataProvider =
- Provider.of<DataProvider>(context, listen: false);
- return Scaffold(
- appBar: AppBar(
- title: Text(I18N.of("打卡时段")),
- ),
- body: Padding(
- padding: EdgeInsets.all(16),
- child: ListView(
- children: <Widget>[
- ListTile(
- leading: Icon(Icons.wb_sunny),
- title: Text(I18N.of("起床打卡")),
- subtitle: Text(
- "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.getUpTimeStart)} - ${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.getUpTimeEnd!)}"),
- trailing: Icon(Icons.chevron_right),
- onTap: () async {
- await PopMenus.baseMenu(
- context: context,
- title: Text(I18N.of("起床打卡时间")),
- contentPadding: EdgeInsets.all(16),
- children: [
- TextButton(
- child: Text(I18N.of("起始时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.getUpTimeStart)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.getUpTimeStart =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- TextButton(
- child: Text(I18N.of("结束时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.getUpTimeEnd!)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.getUpTimeEnd =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- ],
- );
- },
- ),
- ListTile(
- leading: Icon(Icons.free_breakfast),
- title: Text(I18N.of("早饭打卡")),
- subtitle: Text(
- "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.breakfastTimeStart)} - ${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.breakfastTimeEnd!)}"),
- trailing: Icon(Icons.chevron_right),
- onTap: () async {
- await PopMenus.baseMenu(
- context: context,
- title: Text(I18N.of("早饭打卡时间")),
- contentPadding: EdgeInsets.all(16),
- children: [
- TextButton(
- child: Text(I18N.of("起始时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.breakfastTimeStart)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.breakfastTimeStart =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- TextButton(
- child: Text(I18N.of("结束时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.breakfastTimeEnd!)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.breakfastTimeEnd =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- ],
- );
- },
- ),
- ListTile(
- leading: Icon(Icons.local_dining),
- title: Text(I18N.of("午饭打卡")),
- subtitle: Text(
- "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.lunchTimeStart)} - ${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.lunchTimeEnd!)}"),
- trailing: Icon(Icons.chevron_right),
- onTap: () async {
- await PopMenus.baseMenu(
- context: context,
- title: Text(I18N.of("午饭打卡时间")),
- contentPadding: EdgeInsets.all(16),
- children: [
- TextButton(
- child: Text(I18N.of("起始时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.lunchTimeStart)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.lunchTimeStart =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- TextButton(
- child: Text(I18N.of("结束时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.lunchTimeEnd!)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.lunchTimeEnd =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- ],
- );
- },
- ),
- ListTile(
- leading: Icon(Icons.local_hotel),
- title: Text(I18N.of("午休打卡")),
- subtitle: Text(
- "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.midRestTimeStart)} - ${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.midRestTimeEnd!)}"),
- trailing: Icon(Icons.chevron_right),
- onTap: () async {
- await PopMenus.baseMenu(
- context: context,
- title: Text(I18N.of("午休打卡时间")),
- contentPadding: EdgeInsets.all(16),
- children: [
- TextButton(
- child: Text(I18N.of("起始时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.midRestTimeStart)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.midRestTimeStart =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- TextButton(
- child: Text(I18N.of("结束时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.midRestTimeEnd!)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.midRestTimeEnd =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- ],
- );
- },
- ),
- ListTile(
- leading: Icon(Icons.restaurant),
- title: Text(I18N.of("晚饭打卡")),
- subtitle: Text(
- "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.dinnerTimeStart)} - ${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.dinnerTimeEnd!)}"),
- trailing: Icon(Icons.chevron_right),
- onTap: () async {
- await PopMenus.baseMenu(
- context: context,
- title: Text(I18N.of("起床打卡时间")),
- contentPadding: EdgeInsets.all(16),
- children: [
- TextButton(
- child: Text(I18N.of("起始时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.dinnerTimeStart)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.dinnerTimeStart =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- TextButton(
- child: Text(I18N.of("结束时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.dinnerTimeEnd!)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.dinnerTimeEnd =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- ],
- );
- },
- ),
- ListTile(
- leading: Icon(Icons.brightness_4),
- title: Text(I18N.of("晚安打卡")),
- subtitle: Text(
- "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.restTimeStart)} - ${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.restTimeEnd!)}"),
- trailing: Icon(Icons.chevron_right),
- onTap: () async {
- await PopMenus.baseMenu(
- context: context,
- title: Text(I18N.of("起床打卡时间")),
- contentPadding: EdgeInsets.all(16),
- children: [
- TextButton(
- child: Text(I18N.of("起始时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.restTimeStart)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.restTimeStart =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- TextButton(
- child: Text(I18N.of("结束时间")),
- onPressed: () async {
- TimeOfDay? res = await showTimePicker(
- context: context,
- initialTime: TimeOfDay.fromDateTime(
- DateTime.fromMillisecondsSinceEpoch(
- configProvider.restTimeEnd!)),
- );
- if (res != null) {
- Navigator.of(context).pop();
- configProviderUnListen.restTimeEnd =
- DateTime(1, 1, 1, res.hour, res.minute)
- .millisecondsSinceEpoch;
- configProviderUnListen.store();
- configProviderUnListen.refresh();
- await dataProvider.loadLifeInfoData();
- await dataProvider.evaluateToday();
- await Provider.of<NotificationProvider>(context, listen: false).refresh();
- }
- },
- ),
- ],
- );
- },
- ),
- ],
- ),
- ),
- );
- }
- }
|