view.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  4. import 'package:vitalapp/components/appbar.dart';
  5. import 'package:vitalapp/rpc.dart';
  6. import 'blank_door.dart';
  7. import 'controller.dart';
  8. /// 后面管理页
  9. class AdminPage extends GetView<AdminController> {
  10. const AdminPage({super.key});
  11. @override
  12. Widget build(BuildContext context) {
  13. return Scaffold(
  14. appBar: VAppBar(
  15. titleText: "Blank Door",
  16. actions: [
  17. TextButton.icon(
  18. onPressed: () {
  19. BlankDoor.reset();
  20. Get.back();
  21. },
  22. icon: Icon(
  23. Icons.restore,
  24. size: 32,
  25. color: Colors.white,
  26. ),
  27. label: Text(
  28. "Reset",
  29. style: TextStyle(
  30. color: Colors.white,
  31. ),
  32. ),
  33. ),
  34. ],
  35. ),
  36. body: ListView(
  37. padding: const EdgeInsets.symmetric(horizontal: 40),
  38. children: [
  39. const Text("欢迎补充", style: TextStyle(fontSize: 26)),
  40. const SizedBox(height: 8),
  41. _buildNetOnlineControl(),
  42. const SizedBox(height: 8),
  43. _buildDeviceLogControl(),
  44. if (controller.state.isDeveloper) ...[
  45. const SizedBox(height: 8),
  46. _buildDbCpControl(),
  47. const SizedBox(height: 8),
  48. _buildServerControl(),
  49. ],
  50. ],
  51. ),
  52. );
  53. }
  54. Widget _buildNetOnlineControl() {
  55. return Row(
  56. mainAxisAlignment: MainAxisAlignment.center,
  57. children: [
  58. Text("Network Online: "),
  59. Obx(
  60. () => Switch(
  61. value: controller.state.isNetOnline,
  62. onChanged: (value) {
  63. controller.switchOnlineOffline();
  64. },
  65. ),
  66. ),
  67. ],
  68. );
  69. }
  70. Widget _buildDeviceLogControl() {
  71. return Row(
  72. mainAxisAlignment: MainAxisAlignment.center,
  73. children: [
  74. Text("DeviceLog Enable: "),
  75. Obx(
  76. () => Switch(
  77. value: controller.state.isDeviceLogEnable,
  78. onChanged: (value) {
  79. controller.setLogSwitch();
  80. },
  81. ),
  82. ),
  83. ],
  84. );
  85. }
  86. Widget _buildDbCpControl() {
  87. return Row(
  88. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  89. children: [
  90. ElevatedButton(
  91. onPressed: controller.cpDbFileLoki,
  92. child: const Text("Loki CP DB Out"),
  93. ),
  94. ElevatedButton(
  95. onPressed: controller.cpDbFileFinlay,
  96. child: const Text("Finlay CP DB In"),
  97. ),
  98. ],
  99. );
  100. }
  101. Widget _buildServerControl() {
  102. return Row(
  103. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  104. children: [
  105. ElevatedButton(
  106. onPressed: () {
  107. final host = rpc.currentHostAddress;
  108. if (host.contains('@_@')) {
  109. PromptBox.toast("已关闭");
  110. return;
  111. }
  112. final uri = Uri.parse(host);
  113. rpc.setServerHost(
  114. "${uri.host}:${uri.port}@_@", uri.scheme == 'https');
  115. rpc.clearCache();
  116. },
  117. child: const Text("CloseServer"),
  118. ),
  119. ElevatedButton(
  120. onPressed: () {
  121. final host = rpc.currentHostAddress.replaceAll('@_@', '');
  122. final uri = Uri.parse(host);
  123. rpc.setServerHost("${uri.host}:${uri.port}", uri.scheme == 'https');
  124. rpc.clearCache();
  125. PromptBox.toast("已开启");
  126. },
  127. child: const Text("OpenServer"),
  128. ),
  129. ],
  130. );
  131. }
  132. }