1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import 'package:flutter/material.dart';
- import 'package:lszlgl/base/base_state.dart';
- import 'package:lszlgl/service/upgrade_service.dart';
- import 'package:lszlgl/widget/button.dart';
- import 'package:lszlgl/widget/card_item.dart';
- import 'package:package_info_plus/package_info_plus.dart';
- /// 设置
- class SettingPage extends StatefulWidget {
- const SettingPage({Key? key}) : super(key: key);
- @override
- State<SettingPage> createState() => _SettingPageState();
- }
- class _SettingPageState extends BaseState<SettingPage> {
- bool sound = true;
- bool shake = true;
- String version = '';
- void onSave() {
- MyNavigator.showToast('保存成功');
- MyNavigator.pop();
- }
- void onVersionTap() async {
- UpgradeService.checkUpgrade(true);
- }
- @override
- void initState() {
- super.initState();
- PackageInfo.fromPlatform().then((packageInfo) {
- setState(() {
- version = packageInfo.version;
- });
- });
- }
- @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$version', onTap: onVersionTap),
- ],
- ),
- );
- }
- Widget buildSwitch(bool value, ValueChanged changed) {
- return SizedBox(
- height: 24,
- child: Switch(value: value, onChanged: changed),
- );
- }
- }
|