import 'package:flutter/material.dart'; import 'package:lszlgl/base/base_state.dart'; import 'package:lszlgl/config/app_config.dart'; import 'package:lszlgl/service/upgrade_service.dart'; import 'package:lszlgl/widget/button.dart'; import 'package:lszlgl/widget/card_item.dart'; /// 设置 class SettingPage extends StatefulWidget { const SettingPage({Key? key}) : super(key: key); @override State createState() => _SettingPageState(); } class _SettingPageState extends BaseState { bool sound = true; bool shake = true; void onSave() { MyNavigator.showToast('保存成功'); MyNavigator.pop(); } void onVersionTap() async { UpgradeService.checkUpgrade(true); } @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return myScaffold(child: buildBody()); } Widget buildBody() { return Column( children: [ myAppBar(title: '设置'), buildList(), const SizedBox(height: 40), MyButton( '保存', onTap: onSave, gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]), alignment: Alignment.center, minHeight: 40, margin: const EdgeInsets.symmetric(horizontal: 24), ), ], ); } Widget buildList() { return Container( margin: const EdgeInsets.symmetric(horizontal: 12), clipBehavior: Clip.hardEdge, decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(8))), child: Column( children: [ const CardItemWidget('消息设置'), CardItemWidget( '声音', rightChild: buildSwitch(sound, (value) => setState(() => sound = value)), bottomLine: true, ), CardItemWidget( '震动', rightChild: buildSwitch(shake, (value) => setState(() => shake = value)), bottomLine: true, ), CardItemWidget('版本信息', rightText: 'V${AppConfig.packageInfo.version}', onTap: onVersionTap), ], ), ); } Widget buildSwitch(bool value, ValueChanged changed) { return SizedBox( height: 24, child: Switch(value: value, onChanged: changed), ); } }