setting_page.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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(bool show, {bool pop=false}) async {
  23. UpgradeService.checkUpgrade(show, pop: pop);
  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}',
  77. onTap: (){
  78. onVersionTap(true,pop: false);
  79. },
  80. bottomLine: true,
  81. ),
  82. CardItemWidget('更新内容',
  83. rightChild: const Icon(Icons.keyboard_arrow_right,size: 24, color: Color(0xFF01B2C8)),
  84. onTap: (){
  85. onVersionTap(true,pop: true);
  86. },
  87. ),
  88. ],
  89. ),
  90. );
  91. }
  92. Widget buildSwitch(bool value, ValueChanged changed) {
  93. return SizedBox(
  94. height: 24,
  95. child: CupertinoSwitch(value: value, onChanged: changed),
  96. );
  97. }
  98. Widget buildTit() {
  99. return Padding(
  100. padding: const EdgeInsets.all(12.0),
  101. child: Stack(
  102. alignment: Alignment.bottomLeft,
  103. children: [
  104. Container(
  105. height: 10,
  106. width: 78,
  107. decoration: const BoxDecoration(
  108. gradient: LinearGradient(
  109. colors: [Color(0xCC2379F8), Colors.white],
  110. ),
  111. ),
  112. ),
  113. const SizedBox(
  114. width: double.infinity,
  115. child: Text(
  116. '消息设置',
  117. style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  118. ),
  119. )
  120. ],
  121. ),
  122. );
  123. }
  124. }