main.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'package:flutter/services.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vnote_device_plugin/models/device.dart';
  6. import 'package:vnote_device_plugin/vnote_device_plugin.dart';
  7. import 'package:vnote_device_plugin_example/search.dart';
  8. import 'package:vnote_device_plugin_example/sp_o2.dart';
  9. import 'package:vnote_device_plugin_example/sugar.dart';
  10. import 'package:vnote_device_plugin_example/twelve_heart.dart';
  11. import 'package:vnote_device_plugin_example/urine.dart';
  12. import 'package:vnote_device_plugin_example/weight_height.dart';
  13. import 'package:vnote_device_plugin_example/widgets/demo.dart';
  14. import 'device.dart';
  15. import 'global.dart';
  16. import 'heart.dart';
  17. import 'ic_reader.dart';
  18. import 'nibp.dart';
  19. import 'temp.dart';
  20. import 'weight.dart';
  21. void main() {
  22. runApp(const MyApp());
  23. }
  24. class MyApp extends StatefulWidget {
  25. const MyApp({super.key});
  26. @override
  27. State<MyApp> createState() => _MyAppState();
  28. }
  29. class _MyAppState extends State<MyApp> {
  30. String _platformVersion = 'Unknown';
  31. DeviceInfo? _deviceInfo;
  32. final _vnoteDevicePlugin = VnoteDevicePlugin();
  33. static const List<String> _typeValues = [
  34. "temp",
  35. "weight",
  36. "sugar",
  37. "spo2",
  38. "nibp",
  39. "heart",
  40. "urine",
  41. "ic_reader",
  42. "twelveheart",
  43. "weight_height",
  44. ];
  45. static const List<String> _typeNames = [
  46. "体温",
  47. "体重",
  48. "血糖",
  49. "血氧",
  50. "血压",
  51. "心电",
  52. "尿液",
  53. "人证",
  54. "12导心电",
  55. "身高体重",
  56. ];
  57. int _typeIndex = 0;
  58. @override
  59. void initState() {
  60. super.initState();
  61. initPlatformState();
  62. }
  63. Future<void> initPlatformState() async {
  64. String platformVersion;
  65. try {
  66. platformVersion = await _vnoteDevicePlugin.getPlatformVersion() ??
  67. 'Unknown platform version';
  68. await Global.init();
  69. } on PlatformException {
  70. platformVersion = 'Failed to get platform version.';
  71. }
  72. if (!mounted) return;
  73. setState(() {
  74. _platformVersion = platformVersion;
  75. });
  76. }
  77. @override
  78. Widget build(BuildContext context) {
  79. return GetMaterialApp(
  80. home: Scaffold(
  81. appBar: AppBar(
  82. title: const Text('Plugin example app'),
  83. actions: [
  84. IconButton(
  85. onPressed: () async {
  86. // VnoteDevicePluginPlatform.instance.callAction(
  87. // "SEARCH_STOP",
  88. // {
  89. // "TYPE": "temp",
  90. // },
  91. // );
  92. Get.put<DevicesSettingController>(DevicesSettingController());
  93. await Get.to(() => const DevicesSettingPage());
  94. Get.delete<DevicesSettingController>();
  95. },
  96. icon: const Icon(Icons.stop),
  97. ),
  98. ],
  99. ),
  100. body: Center(
  101. child: Column(
  102. mainAxisAlignment: MainAxisAlignment.center,
  103. crossAxisAlignment: CrossAxisAlignment.center,
  104. children: [
  105. // Text('Running on: $_platformVersion\n'),
  106. _buildTypeSelect(),
  107. const SizedBox(height: 8),
  108. DeviceCard(data: _deviceInfo),
  109. if (_deviceInfo != null) ...[
  110. const SizedBox(height: 8),
  111. _buildExamCard(),
  112. ],
  113. ],
  114. ),
  115. ),
  116. floatingActionButton: FloatingActionButton(
  117. onPressed: () async {
  118. final result = await SearchDialog.dialog(_typeValues[_typeIndex]);
  119. if (result != null) {
  120. setState(() {
  121. _deviceInfo = result;
  122. });
  123. } else {
  124. //
  125. }
  126. },
  127. child: Column(
  128. mainAxisAlignment: MainAxisAlignment.center,
  129. children: const [
  130. Icon(Icons.search),
  131. Text(
  132. "搜索",
  133. style: TextStyle(fontSize: 12),
  134. ),
  135. ],
  136. ),
  137. ),
  138. ),
  139. );
  140. }
  141. Widget _buildTypeSelect() {
  142. final items = <DropdownMenuItem<int>>[];
  143. for (var i = 0; i < _typeValues.length; i++) {
  144. items.add(
  145. DropdownMenuItem<int>(
  146. value: i,
  147. child: Text(_typeNames[i]),
  148. ),
  149. );
  150. }
  151. selectedBuilder(BuildContext context) {
  152. final widgets = <Widget>[];
  153. for (var i = 0; i < _typeValues.length; i++) {
  154. TextStyle? style;
  155. if (i == _typeIndex) {
  156. style = TextStyle(
  157. color: Theme.of(context).primaryColor,
  158. fontWeight: FontWeight.bold,
  159. );
  160. }
  161. widgets.add(Text(_typeNames[i], style: style));
  162. }
  163. return widgets;
  164. }
  165. return Container(
  166. alignment: Alignment.center,
  167. // width: 120,
  168. height: 30,
  169. // decoration: BoxDecoration(
  170. // border: Border.all(),
  171. // borderRadius: BorderRadius.circular(8),
  172. // ),
  173. child: DropdownButton<int>(
  174. // underline: SizedBox(),
  175. items: items,
  176. value: _typeIndex,
  177. selectedItemBuilder: selectedBuilder,
  178. onChanged: (index) {
  179. if (index != null) {
  180. setState(() {
  181. _typeIndex = index;
  182. _deviceInfo = null;
  183. });
  184. }
  185. },
  186. ),
  187. );
  188. }
  189. Widget _buildExamCard() {
  190. final type = _typeValues[_typeIndex];
  191. switch (type) {
  192. case "temp":
  193. return TempCard(
  194. mac: _deviceInfo!.mac,
  195. model: _deviceInfo!.model,
  196. );
  197. case "weight":
  198. return WeightCard(
  199. mac: _deviceInfo!.mac,
  200. model: _deviceInfo!.model,
  201. );
  202. case "sugar":
  203. return SugarCard(
  204. mac: _deviceInfo!.mac,
  205. model: _deviceInfo!.model,
  206. );
  207. case "spo2":
  208. return SpO2Card(
  209. mac: _deviceInfo!.mac,
  210. model: _deviceInfo!.model,
  211. );
  212. case "nibp":
  213. return NibpCard(
  214. mac: _deviceInfo!.mac,
  215. model: _deviceInfo!.model,
  216. );
  217. case "heart":
  218. return HeartCard(
  219. mac: _deviceInfo!.mac,
  220. model: _deviceInfo!.model,
  221. );
  222. case "urine":
  223. return UrineCard(
  224. mac: _deviceInfo!.mac,
  225. model: _deviceInfo!.model,
  226. );
  227. case "ic_reader":
  228. return ICReaderCard(
  229. mac: _deviceInfo!.mac,
  230. model: _deviceInfo!.model,
  231. );
  232. case "twelveheart":
  233. return TwelveHeartCard(
  234. mac: _deviceInfo!.mac,
  235. model: _deviceInfo!.model,
  236. );
  237. case "weight_height":
  238. return WeightHeightCard(
  239. mac: _deviceInfo!.mac,
  240. model: _deviceInfo!.model,
  241. );
  242. default:
  243. return const SizedBox();
  244. }
  245. }
  246. }