setting_page.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:lszlgl/base/base_state.dart';
  4. import 'package:lszlgl/config/app_config.dart';
  5. import 'package:lszlgl/network/my_api.dart';
  6. import 'package:lszlgl/service/upgrade_service.dart';
  7. import 'package:lszlgl/widget/button.dart';
  8. import 'package:lszlgl/widget/card_item.dart';
  9. /// 设置
  10. class SettingPage extends StatefulWidget {
  11. const SettingPage({Key? key}) : super(key: key);
  12. @override
  13. State<SettingPage> createState() => _SettingPageState();
  14. }
  15. class _SettingPageState extends BaseState<SettingPage> {
  16. bool sound = true;
  17. bool shake = true;
  18. void onSave() {
  19. MyNavigator.showToast('保存成功');
  20. MyNavigator.pop();
  21. }
  22. void onVersionTap() async {
  23. UpgradeService.checkUpgrade(true);
  24. }
  25. @override
  26. void initState() {
  27. super.initState();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return myScaffold(child: buildBody());
  32. }
  33. Widget buildBody() {
  34. return Column(
  35. children: [
  36. myAppBar(title: '设置'),
  37. buildList(),
  38. const SizedBox(height: 40),
  39. MyButton(
  40. '保 存',
  41. radius: 10,
  42. onTap: onSave,
  43. gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]),
  44. alignment: Alignment.center,
  45. minHeight: 40,
  46. margin: const EdgeInsets.symmetric(horizontal: 12),
  47. ),
  48. if(AppConfig.env == AppEnvironment.develop)
  49. Padding(
  50. padding: const EdgeInsets.only(top: 38.0),
  51. child: Text(MyApi.testUrl,style: const TextStyle(color: Color(0xFFA4A4A4),fontSize: 12),),
  52. )
  53. ],
  54. );
  55. }
  56. Widget buildList() {
  57. return Container(
  58. margin: const EdgeInsets.symmetric(horizontal: 12),
  59. clipBehavior: Clip.hardEdge,
  60. decoration: const BoxDecoration(
  61. color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8))),
  62. child: Column(
  63. children: [
  64. buildTit(),
  65. CardItemWidget(
  66. '声音',
  67. rightChild: buildSwitch(sound, (value) => setState(() => sound = value)),
  68. bottomLine: true,
  69. ),
  70. CardItemWidget(
  71. '震动',
  72. rightChild: buildSwitch(shake, (value) => setState(() => shake = value)),
  73. bottomLine: true,
  74. ),
  75. CardItemWidget('版本信息',
  76. rightText: 'V${AppConfig.packageInfo.version}', onTap: onVersionTap),
  77. ],
  78. ),
  79. );
  80. }
  81. Widget buildSwitch(bool value, ValueChanged changed) {
  82. return SizedBox(
  83. height: 24,
  84. child: CupertinoSwitch(value: value, onChanged: changed),
  85. );
  86. }
  87. Widget buildTit() {
  88. return Padding(
  89. padding: const EdgeInsets.all(12.0),
  90. child: Stack(
  91. alignment: Alignment.bottomLeft,
  92. children: [
  93. Container(
  94. height: 10,
  95. width: 78,
  96. decoration: const BoxDecoration(
  97. gradient: LinearGradient(
  98. colors: [Color(0xCC2379F8), Colors.white],
  99. ),
  100. ),
  101. ),
  102. const SizedBox(
  103. width: double.infinity,
  104. child: Text(
  105. '消息设置',
  106. style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  107. ),
  108. )
  109. ],
  110. ),
  111. );
  112. }
  113. }