message_setting_page.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import 'package:flutter/material.dart';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. import 'package:sport/widgets/appbar.dart';
  4. import 'package:sport/widgets/list_tile.dart';
  5. class MessageSettingPage extends StatefulWidget {
  6. @override
  7. State<StatefulWidget> createState() => _PageState();
  8. }
  9. class _PageState extends State<MessageSettingPage> {
  10. bool _message = true;
  11. @override
  12. void initState() {
  13. super.initState();
  14. loadSetting();
  15. }
  16. void loadSetting() {
  17. SharedPreferences.getInstance().then((value) {
  18. _message = value.getBool("message_setting") ?? true;
  19. setState(() {});
  20. });
  21. }
  22. @override
  23. Widget build(BuildContext context) {
  24. const contentPadding = EdgeInsets.symmetric(horizontal: 0.0);
  25. return Scaffold(
  26. backgroundColor: Colors.white,
  27. body: CustomScrollView(
  28. slivers: <Widget>[
  29. buildSliverAppBar(context, "消息提醒"),
  30. SliverPadding(
  31. padding: const EdgeInsets.symmetric(horizontal: 12),
  32. sliver: SliverToBoxAdapter(
  33. child: Column(
  34. children: <Widget>[
  35. ListView(
  36. padding: EdgeInsets.zero,
  37. physics: NeverScrollableScrollPhysics(),
  38. shrinkWrap: true,
  39. children: divideTiles(
  40. context: context,
  41. includeLast: true,
  42. tiles: [
  43. ListTile(
  44. title: Text('信息通知提醒'),
  45. trailing: Switch(
  46. value: _message,
  47. onChanged: (bool value) {
  48. SharedPreferences.getInstance().then((prefs) {
  49. _message = value;
  50. prefs.setBool("message_setting", value);
  51. setState(() {});
  52. });
  53. },
  54. ),
  55. contentPadding: contentPadding,
  56. ),
  57. ],
  58. ).toList(),
  59. ),
  60. ],
  61. ),
  62. ),
  63. ),
  64. ],
  65. ));
  66. }
  67. }