setting_page.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import 'package:cpt_profile/modules/me/setting/setting_state.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:plugin_basic/base/base_state.dart';
  5. import 'package:plugin_basic/base/base_stateful_page.dart';
  6. import 'package:plugin_basic/service/app_config_service.dart';
  7. import 'package:plugin_basic/service/user_service.dart';
  8. import 'package:plugin_basic/utils/ext_get_nav.dart';
  9. import 'package:cs_resources/constants/color_constants.dart';
  10. import 'package:router/path/router_path.dart';
  11. import 'package:shared/utils/log_utils.dart';
  12. import 'package:widgets/ext/ex_widget.dart';
  13. import 'package:widgets/my_appbar.dart';
  14. import 'package:widgets/utils/dark_theme_util.dart';
  15. import '../dark_model/dark_model_page.dart';
  16. import '../notification_enable/notification_enable_page.dart';
  17. import '../reset_password/reset_password_page.dart';
  18. import 'setting_controller.dart';
  19. class SettingPage extends BaseStatefulPage<SettingController> {
  20. SettingPage({super.key});
  21. //启动当前页面
  22. static void startInstance() {
  23. return Get.start(RouterPath.SETTING);
  24. }
  25. @override
  26. State<SettingPage> createState() => _SettingPageState();
  27. @override
  28. SettingController createRawController() {
  29. return SettingController();
  30. }
  31. }
  32. class _SettingPageState extends BaseState<SettingPage, SettingController> {
  33. late SettingState state;
  34. @override
  35. void initState() {
  36. super.initState();
  37. state = controller.state;
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. return Scaffold(
  42. appBar: MyAppBar.appBar(context, "设置".tr),
  43. body: SafeArea(
  44. bottom: true,
  45. top: false,
  46. //真正的 Content 布局
  47. child: Scrollbar(
  48. child: SingleChildScrollView(
  49. child: Container(
  50. margin: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
  51. decoration: BoxDecoration(
  52. color: DarkThemeUtil.multiColors(ColorConstants.white, darkColor: ColorConstants.darkBlackItem),
  53. borderRadius: BorderRadius.circular(10),
  54. boxShadow: [
  55. BoxShadow(color: hexToColor('#000000', opacity: 0.1), blurRadius: 7),
  56. ],
  57. ),
  58. child: Column(
  59. mainAxisSize: MainAxisSize.min,
  60. children: [
  61. Obx(() {
  62. return _buildItem(
  63. '实名认证'.tr,
  64. state.getVerifyStatusText(UserService.to.getUserProfile.name),
  65. () async {
  66. Log.d("进入实名认证页面");
  67. },
  68. );
  69. }),
  70. Obx(() {
  71. return _buildItem(UserService.to.passwordType.value == 'change' ? '修改密码'.tr : '设置密码'.tr, '', () {
  72. ResetPasswordPage.startInstance(UserService.to.passwordType.value);
  73. });
  74. }),
  75. _buildItem('修改手机号'.tr, '', () {
  76. Get.toNamed(RouterPath.CHANGEMOBILE);
  77. }),
  78. _buildItem('深色模式'.tr, '', () {
  79. DarkModelPage.startInstance();
  80. }),
  81. _buildItem('消息推送'.tr, '', () {
  82. NotificationEnablePage.startInstance();
  83. }),
  84. autoCtlGetBuilder(builder: (controller) {
  85. return _buildItem('清除缓存'.tr, state.appSize, () {
  86. controller.clearCache();
  87. }, isShowNextIcon: false);
  88. }),
  89. _buildItem('版本号'.tr, 'v ${ConfigService.to.version}', () {}, isShowNextIcon: false),
  90. Container(
  91. height: 40,
  92. width: double.infinity,
  93. margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 25),
  94. color: hexToColor('#0689FB'),
  95. child: Center(
  96. child: Text("退出".tr, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white)),
  97. ),
  98. ).onTap(() {
  99. controller.showLogoutDialog();
  100. })
  101. ],
  102. ),
  103. ),
  104. ),
  105. ),
  106. ));
  107. }
  108. Widget _buildItem(String title, String des, VoidCallback action, {bool isShowNextIcon = true}) {
  109. return GestureDetector(
  110. behavior: HitTestBehavior.opaque,
  111. onTap: () {
  112. action();
  113. },
  114. child: Container(
  115. padding: const EdgeInsets.symmetric(horizontal: 20),
  116. child: Column(
  117. children: [
  118. Container(
  119. padding: const EdgeInsets.symmetric(vertical: 15),
  120. child: Row(
  121. children: [
  122. Text(
  123. title.tr,
  124. style: TextStyle(
  125. fontSize: 14,
  126. fontWeight: FontWeight.w500,
  127. color: DarkThemeUtil.multiColors(ColorConstants.black, darkColor: ColorConstants.white)),
  128. ),
  129. const Spacer(),
  130. Visibility(
  131. visible: des.isNotEmpty,
  132. child: Text(
  133. des.tr,
  134. style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: hexToColor('#0689FB')),
  135. ),
  136. ),
  137. Visibility(
  138. visible: isShowNextIcon,
  139. child: Icon(Icons.navigate_next_sharp, size: 20, color: hexToColor('#CCCCCC')),
  140. ),
  141. ],
  142. ),
  143. ),
  144. Divider(
  145. color: DarkThemeUtil.multiColors(hexToColor('#EDEDED'), darkColor: ColorConstants.darkBlackItemDivider),
  146. height: 0.5,
  147. )
  148. ],
  149. ),
  150. ),
  151. );
  152. }
  153. }