NotificationSetPage.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_habit/common/I18N.dart';
  3. import 'package:flutter_habit/provider/ConfigProvider.dart';
  4. import 'package:flutter_habit/provider/NotificationProvider.dart';
  5. import 'package:flutter_habit/common/utils/ConvertUtils.dart';
  6. import 'package:provider/provider.dart';
  7. class NotificationSetPage extends StatefulWidget {
  8. @override
  9. _NotificationSetPageState createState() => _NotificationSetPageState();
  10. }
  11. class _NotificationSetPageState extends State<NotificationSetPage> {
  12. @override
  13. Widget build(BuildContext context) {
  14. ConfigProvider configProvider =
  15. Provider.of<ConfigProvider>(context, listen: true);
  16. NotificationProvider notificationProvider =
  17. Provider.of<NotificationProvider>(context, listen: true);
  18. NotificationProvider notificationProviderUnListen =
  19. Provider.of<NotificationProvider>(context, listen: false);
  20. return Scaffold(
  21. appBar: AppBar(
  22. title: Text(I18N.of("通知开关")),
  23. ),
  24. body: Padding(
  25. padding: EdgeInsets.all(16),
  26. child: ListView(
  27. children: <Widget>[
  28. ListTile(
  29. leading: Icon(Icons.wb_sunny),
  30. title: Text(I18N.of("起床打卡")),
  31. subtitle: Text(
  32. "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.getUpTimeStart)}"),
  33. trailing: Switch(
  34. value: notificationProvider.getUpNotification,
  35. onChanged: (bool value) async {
  36. notificationProviderUnListen.getUpNotification = value;
  37. await notificationProviderUnListen.refresh();
  38. },
  39. ),
  40. ),
  41. ListTile(
  42. leading: Icon(Icons.free_breakfast),
  43. title: Text(I18N.of("早饭打卡")),
  44. subtitle: Text(
  45. "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.breakfastTimeStart)}"),
  46. trailing: Switch(
  47. value: notificationProvider.breakfastNotification,
  48. onChanged: (bool value) async {
  49. notificationProviderUnListen.breakfastNotification = value;
  50. await notificationProviderUnListen.refresh();
  51. },
  52. ),
  53. ),
  54. ListTile(
  55. leading: Icon(Icons.local_dining),
  56. title: Text(I18N.of("午饭打卡")),
  57. subtitle: Text(
  58. "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.lunchTimeStart)}"),
  59. trailing: Switch(
  60. value: notificationProvider.lunchNotification,
  61. onChanged: (bool value) async {
  62. notificationProviderUnListen.lunchNotification = value;
  63. await notificationProviderUnListen.refresh();
  64. },
  65. ),
  66. ),
  67. ListTile(
  68. leading: Icon(Icons.local_hotel),
  69. title: Text(I18N.of("午休打卡")),
  70. subtitle: Text(
  71. "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.midRestTimeStart)}"),
  72. trailing: Switch(
  73. value: notificationProvider.midRestNotification,
  74. onChanged: (bool value) async {
  75. notificationProviderUnListen.midRestNotification = value;
  76. await notificationProviderUnListen.refresh();
  77. },
  78. ),
  79. ),
  80. ListTile(
  81. leading: Icon(Icons.restaurant),
  82. title: Text(I18N.of("晚饭打卡")),
  83. subtitle: Text(
  84. "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.dinnerTimeStart)}"),
  85. trailing: Switch(
  86. value: notificationProvider.dinnerNotification,
  87. onChanged: (bool value) async {
  88. notificationProviderUnListen.dinnerNotification = value;
  89. await notificationProviderUnListen.refresh();
  90. },
  91. ),
  92. ),
  93. ListTile(
  94. leading: Icon(Icons.brightness_4),
  95. title: Text(I18N.of("晚安打卡")),
  96. subtitle: Text(
  97. "${ConvertUtils.timeFormMillisecondsSinceEpoch(configProvider.restTimeStart)}"),
  98. trailing: Switch(
  99. value: notificationProvider.restNotification,
  100. onChanged: (bool value) async {
  101. notificationProviderUnListen.restNotification = value;
  102. await notificationProviderUnListen.refresh();
  103. },
  104. ),
  105. ),
  106. ],
  107. ),
  108. ),
  109. );
  110. }
  111. }