import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:lszlgl/base/base_state.dart'; import 'package:lszlgl/config/app_config.dart'; import 'package:lszlgl/config/colors.dart'; import 'package:lszlgl/network/my_api.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( '保 存', radius: 10, onTap: onSave, gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]), alignment: Alignment.center, minHeight: 40, margin: const EdgeInsets.symmetric(horizontal: 12), ), if(AppConfig.env == AppEnvironment.develop) Padding( padding: const EdgeInsets.only(top: 38.0), child: Text(MyApi.testUrl,style: const TextStyle(color: Color(0xFFA4A4A4),fontSize: 12),), ) ], ); } Widget buildList() { return Container( margin: const EdgeInsets.symmetric(horizontal: 12), clipBehavior: Clip.hardEdge, decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8))), child: Column( children: [ buildTit(), 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: CupertinoSwitch(value: value, onChanged: changed), ); } Widget buildTit() { return Padding( padding: const EdgeInsets.all(12.0), child: Stack( alignment: Alignment.bottomLeft, children: [ Container( height: 10, width: 78, decoration: const BoxDecoration( gradient: LinearGradient( colors: [Color(0xCC2379F8), Colors.white], ), ), ), const SizedBox( width: double.infinity, child: Text( '消息设置', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), ) ], ), ); } }