setting_page.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:shirne_dialog/shirne_dialog.dart';
  4. import '../global.dart';
  5. import '../models/engine_type.dart';
  6. import '../models/engine_level.dart';
  7. import '../models/game_setting.dart';
  8. /// 设置页
  9. class SettingPage extends StatefulWidget {
  10. const SettingPage({Key? key}) : super(key: key);
  11. @override
  12. State<SettingPage> createState() => _SettingPageState();
  13. }
  14. class _SettingPageState extends State<SettingPage> {
  15. GameSetting? setting;
  16. @override
  17. void initState() {
  18. super.initState();
  19. GameSetting.getInstance().then(
  20. (value) => setState(() {
  21. setting = value;
  22. }),
  23. );
  24. }
  25. @override
  26. Widget build(BuildContext context) {
  27. double width = 500;
  28. if (MediaQuery.of(context).size.width < width) {
  29. width = MediaQuery.of(context).size.width;
  30. }
  31. return Scaffold(
  32. appBar: AppBar(
  33. title: Text(context.l10n.settingTitle),
  34. actions: [
  35. TextButton(
  36. onPressed: () {
  37. setting?.save().then((v) {
  38. Navigator.pop(context);
  39. MyDialog.toast('保存成功', iconType: IconType.success);
  40. });
  41. },
  42. child: const Text(
  43. '保存',
  44. style: TextStyle(color: Colors.white),
  45. ),
  46. ),
  47. ],
  48. ),
  49. body: Center(
  50. child: setting == null
  51. ? const CircularProgressIndicator()
  52. : Container(
  53. width: width,
  54. padding: const EdgeInsets.all(20),
  55. child: SingleChildScrollView(
  56. child: ListBody(
  57. children: [
  58. ListTile(
  59. title: const Text('AI类型'),
  60. trailing: CupertinoSegmentedControl(
  61. onValueChanged: (value) {
  62. if (value == null) return;
  63. setState(() {
  64. setting!.robotType = value;
  65. });
  66. },
  67. groupValue: setting!.robotType,
  68. children: const {
  69. EngineType.builtIn: Padding(
  70. padding: EdgeInsets.symmetric(
  71. horizontal: 10,
  72. ),
  73. child: Text('内置引擎'),
  74. ),
  75. EngineType.elephantEye: Padding(
  76. padding: EdgeInsets.symmetric(
  77. horizontal: 10,
  78. ),
  79. child: Text('elephantEye'),
  80. ),
  81. EngineType.pikafish: Padding(
  82. padding: EdgeInsets.symmetric(
  83. horizontal: 10,
  84. ),
  85. child: Text('皮卡鱼'),
  86. ),
  87. },
  88. ),
  89. ),
  90. ListTile(
  91. title: const Text('AI级别'),
  92. trailing: CupertinoSegmentedControl(
  93. onValueChanged: (value) {
  94. if (value == null) return;
  95. setState(() {
  96. setting!.robotLevel = value as int;
  97. });
  98. },
  99. groupValue: setting!.robotLevel,
  100. children: const {
  101. EngineLevel.learn: Padding(
  102. padding: EdgeInsets.symmetric(
  103. horizontal: 10,
  104. ),
  105. child: Text('初级'),
  106. ),
  107. EngineLevel.middle: Padding(
  108. padding: EdgeInsets.symmetric(
  109. horizontal: 10,
  110. ),
  111. child: Text('中级'),
  112. ),
  113. EngineLevel.master: Padding(
  114. padding: EdgeInsets.symmetric(
  115. horizontal: 10,
  116. ),
  117. child: Text('大师'),
  118. )
  119. },
  120. ),
  121. ),
  122. ListTile(
  123. title: const Text('游戏声音'),
  124. trailing: CupertinoSwitch(
  125. value: setting!.sound,
  126. onChanged: (v) {
  127. setState(() {
  128. setting!.sound = v;
  129. });
  130. },
  131. ),
  132. ),
  133. ListTile(
  134. title: const Text('游戏音量'),
  135. trailing: CupertinoSlider(
  136. value: setting!.soundVolume,
  137. min: 0,
  138. max: 1,
  139. onChanged: (v) {
  140. setState(() {
  141. setting!.soundVolume = v;
  142. });
  143. },
  144. ),
  145. ),
  146. ],
  147. ),
  148. ),
  149. ),
  150. ),
  151. );
  152. }
  153. }