setting_page.dart 2.3 KB

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