setting_page.dart 3.3 KB

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