view.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/architecture/app_parameters.dart';
  4. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  5. import 'package:vitalapp/components/appbar.dart';
  6. import 'package:vitalapp/rpc.dart';
  7. import 'package:wifi_iot/wifi_iot.dart';
  8. import 'blank_door.dart';
  9. import 'controller.dart';
  10. /// 后面管理页
  11. class AdminPage extends GetView<AdminController> {
  12. const AdminPage({super.key});
  13. @override
  14. Widget build(BuildContext context) {
  15. return Scaffold(
  16. appBar: VAppBar(
  17. titleText: "Blank Door",
  18. actions: [
  19. TextButton.icon(
  20. onPressed: () {
  21. BlankDoor.reset();
  22. Get.back();
  23. },
  24. icon: Icon(
  25. Icons.restore,
  26. size: 32,
  27. color: Colors.white,
  28. ),
  29. label: Text(
  30. "Reset",
  31. style: TextStyle(
  32. color: Colors.white,
  33. ),
  34. ),
  35. ),
  36. ],
  37. ),
  38. body: ListView(
  39. padding: const EdgeInsets.symmetric(horizontal: 40),
  40. children: [
  41. const Text("欢迎补充", style: TextStyle(fontSize: 26)),
  42. SizedBox(
  43. height: 40,
  44. child: FutureBuilder(
  45. builder: (context, snapshot) {
  46. if (snapshot.hasData) {
  47. return Text("WIFI: ${snapshot.data ?? "Unknow"}");
  48. }
  49. return Text("WIFI: Loading...");
  50. },
  51. future: WiFiForIoTPlugin.getSSID(),
  52. ),
  53. ),
  54. const SizedBox(height: 8),
  55. _buildIsLocalStation(),
  56. const SizedBox(height: 8),
  57. _buildNetOnlineControl(),
  58. const SizedBox(height: 8),
  59. _buildDeviceLogControl(),
  60. if (controller.state.isDeveloper) ...[
  61. const SizedBox(height: 8),
  62. _buildDbCpControl(),
  63. const SizedBox(height: 8),
  64. _buildServerControl(),
  65. ],
  66. _buildCameraList(),
  67. ],
  68. ),
  69. );
  70. }
  71. Widget _buildIsLocalStation() {
  72. bool isLocalStation = AppParameters.data.isLocalStation;
  73. if (isLocalStation) {
  74. return Text("工作站模式", style: TextStyle(fontSize: 26));
  75. } else {
  76. return Text("一体机模式", style: TextStyle(fontSize: 26));
  77. }
  78. }
  79. Widget _buildNetOnlineControl() {
  80. return Row(
  81. mainAxisAlignment: MainAxisAlignment.center,
  82. children: [
  83. Text("Network Online: "),
  84. Obx(
  85. () => Switch(
  86. value: controller.state.isNetOnline,
  87. onChanged: (value) {
  88. controller.switchOnlineOffline();
  89. },
  90. ),
  91. ),
  92. ],
  93. );
  94. }
  95. Widget _buildDeviceLogControl() {
  96. return Row(
  97. mainAxisAlignment: MainAxisAlignment.center,
  98. children: [
  99. Text("DeviceLog Enable: "),
  100. Obx(
  101. () => Switch(
  102. value: controller.state.isDeviceLogEnable,
  103. onChanged: (value) {
  104. controller.setLogSwitch();
  105. },
  106. ),
  107. ),
  108. ],
  109. );
  110. }
  111. Widget _buildDbCpControl() {
  112. return Row(
  113. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  114. children: [
  115. ElevatedButton(
  116. onPressed: controller.cpDbFileLoki,
  117. child: const Text("Loki CP DB Out"),
  118. ),
  119. ElevatedButton(
  120. onPressed: controller.cpDbFileFinlay,
  121. child: const Text("Finlay CP DB In"),
  122. ),
  123. ],
  124. );
  125. }
  126. Widget _buildServerControl() {
  127. return Row(
  128. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  129. children: [
  130. ElevatedButton(
  131. onPressed: () {
  132. final host = rpc.currentHostAddress;
  133. if (host.contains('@_@')) {
  134. PromptBox.toast("已关闭");
  135. return;
  136. }
  137. final uri = Uri.parse(host);
  138. rpc.setServerHost(
  139. "${uri.host}:${uri.port}@_@", uri.scheme == 'https');
  140. rpc.clearCache();
  141. },
  142. child: const Text("CloseServer"),
  143. ),
  144. ElevatedButton(
  145. onPressed: () {
  146. final host = rpc.currentHostAddress.replaceAll('@_@', '');
  147. final uri = Uri.parse(host);
  148. rpc.setServerHost("${uri.host}:${uri.port}", uri.scheme == 'https');
  149. rpc.clearCache();
  150. PromptBox.toast("已开启");
  151. },
  152. child: const Text("OpenServer"),
  153. ),
  154. ],
  155. );
  156. }
  157. Widget _buildCameraList() {
  158. return Column(
  159. crossAxisAlignment: CrossAxisAlignment.start,
  160. children: [
  161. Row(
  162. children: [
  163. Text("Camera List", style: TextStyle(fontSize: 26)),
  164. SizedBox(width: 20),
  165. ElevatedButton.icon(
  166. label: Text("Detect Camera"),
  167. icon: Icon(
  168. Icons.refresh,
  169. size: 30,
  170. ),
  171. onPressed: () {
  172. controller.detectCamera();
  173. },
  174. ),
  175. ElevatedButton.icon(
  176. label: Text("Open Camera Test Page"),
  177. icon: Icon(
  178. Icons.refresh,
  179. size: 30,
  180. ),
  181. onPressed: () {
  182. controller.openCameraTest();
  183. },
  184. ),
  185. ],
  186. ),
  187. // 多行文本
  188. Obx(() {
  189. if (controller.state.cameraList.isEmpty) {
  190. return Text("No Camera Detected ${controller.state.errorMessage}");
  191. }
  192. return Column(
  193. children: controller.state.cameraList
  194. .map(
  195. (e) => ListTile(
  196. title: Text(e),
  197. ),
  198. )
  199. .toList(),
  200. );
  201. }),
  202. ],
  203. );
  204. }
  205. }