setting_page.dart 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'package:flutter/material.dart';
  2. import 'package:lszlgl/base/base_state.dart';
  3. import 'package:lszlgl/service/upgrade_service.dart';
  4. import 'package:lszlgl/widget/button.dart';
  5. import 'package:lszlgl/widget/card_item.dart';
  6. import 'package:package_info_plus/package_info_plus.dart';
  7. /// 设置
  8. class SettingPage extends StatefulWidget {
  9. const SettingPage({Key? key}) : super(key: key);
  10. @override
  11. State<SettingPage> createState() => _SettingPageState();
  12. }
  13. class _SettingPageState extends BaseState<SettingPage> {
  14. bool sound = true;
  15. bool shake = true;
  16. String version = '';
  17. void onSave() {
  18. MyNavigator.showToast('保存成功');
  19. MyNavigator.pop();
  20. }
  21. void onVersionTap() async {
  22. UpgradeService.checkUpgrade(true);
  23. }
  24. @override
  25. void initState() {
  26. super.initState();
  27. PackageInfo.fromPlatform().then((packageInfo) {
  28. setState(() {
  29. version = packageInfo.version;
  30. });
  31. });
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return myScaffold(child: buildBody());
  36. }
  37. Widget buildBody() {
  38. return Column(
  39. children: [
  40. myAppBar(title: '设置'),
  41. buildList(),
  42. const SizedBox(height: 40),
  43. MyButton(
  44. '保存',
  45. onTap: onSave,
  46. gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]),
  47. alignment: Alignment.center,
  48. minHeight: 40,
  49. margin: const EdgeInsets.symmetric(horizontal: 24),
  50. ),
  51. ],
  52. );
  53. }
  54. Widget buildList() {
  55. return Container(
  56. margin: const EdgeInsets.symmetric(horizontal: 12),
  57. clipBehavior: Clip.hardEdge,
  58. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(8))),
  59. child: Column(
  60. children: [
  61. const CardItemWidget('消息设置'),
  62. CardItemWidget(
  63. '声音',
  64. rightChild: buildSwitch(sound, (value) => setState(() => sound = value)),
  65. bottomLine: true,
  66. ),
  67. CardItemWidget(
  68. '震动',
  69. rightChild: buildSwitch(shake, (value) => setState(() => shake = value)),
  70. bottomLine: true,
  71. ),
  72. CardItemWidget('版本信息', rightText: 'V$version', onTap: onVersionTap),
  73. ],
  74. ),
  75. );
  76. }
  77. Widget buildSwitch(bool value, ValueChanged changed) {
  78. return SizedBox(
  79. height: 24,
  80. child: Switch(value: value, onChanged: changed),
  81. );
  82. }
  83. }