device_info_page.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_blue/flutter_blue.dart';
  4. import 'package:provider/provider.dart';
  5. import 'package:sport/provider/bluetooth.dart';
  6. import 'package:sport/router/navigator_util.dart';
  7. import 'package:sport/services/Converter.dart';
  8. import 'package:sport/widgets/appbar.dart';
  9. import 'package:sport/widgets/box.dart';
  10. import 'package:sport/widgets/dialog/search_device.dart';
  11. import 'package:sport/widgets/image.dart';
  12. import 'package:sport/widgets/loading.dart';
  13. class DeviceInfoPage extends StatefulWidget {
  14. @override
  15. State<StatefulWidget> createState() => _PageState();
  16. }
  17. class _PageState extends State<DeviceInfoPage> {
  18. var labelPadding = const EdgeInsets.symmetric(horizontal: 12.0, vertical: 10.0);
  19. var contentPadding = const EdgeInsets.symmetric(horizontal: 0.0);
  20. @override
  21. void initState() {
  22. super.initState();
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return Scaffold(
  27. body: CustomScrollView(
  28. slivers: <Widget>[
  29. buildSliverAppBar(context, "设备详情", backgroundColor: Theme.of(context).scaffoldBackgroundColor),
  30. SliverToBoxAdapter(
  31. child: Selector<Bluetooth, BluetoothDevice>(
  32. selector: (_, bluetooth) => bluetooth.device,
  33. builder: (_, device, ___) {
  34. return device == null ? RequestLoadingWidget() : _infoWidget(context, device);
  35. })),
  36. ],
  37. ));
  38. }
  39. Widget _infoWidget(BuildContext context, BluetoothDevice device) {
  40. return Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
  41. Padding(
  42. padding: labelPadding,
  43. child: Text("设置", style: Theme.of(context).textTheme.bodyText2),
  44. ),
  45. BoxWidget(
  46. paddingAll: false,
  47. body: ListView(
  48. padding: EdgeInsets.all(0),
  49. physics: NeverScrollableScrollPhysics(),
  50. shrinkWrap: true,
  51. children: ListTile.divideTiles(context: context, tiles: [
  52. ListTile(
  53. title: Row(
  54. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  55. children: <Widget>[
  56. Text("当前设备"),
  57. Text(
  58. "${device.name}",
  59. style: Theme.of(context).textTheme.bodyText2,
  60. )
  61. ],
  62. ),
  63. contentPadding: contentPadding,
  64. onTap: () {},
  65. ),
  66. ListTile(
  67. title: Row(
  68. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  69. children: <Widget>[
  70. Text("设备状态"),
  71. StreamBuilder<BluetoothDeviceState>(
  72. stream: device.state,
  73. initialData: BluetoothDeviceState.connecting,
  74. builder: (c, snapshot) => Text(
  75. (snapshot.data == BluetoothDeviceState.connected) ? "已连接" : "未连接",
  76. style: Theme.of(context).textTheme.bodyText2.copyWith(color: Theme.of(context).accentColor),
  77. ))
  78. ],
  79. ),
  80. contentPadding: contentPadding,
  81. ),
  82. ListTile(
  83. title: Row(
  84. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  85. children: <Widget>[
  86. Text("更换设备"),
  87. ],
  88. ),
  89. contentPadding: contentPadding,
  90. trailing: arrowRight5(),
  91. onTap: () {
  92. showDialog(context: context, child: SearchDeviceDialog());
  93. },
  94. ),
  95. ListTile(
  96. title: Row(
  97. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  98. children: <Widget>[
  99. Text("设备测试"),
  100. ],
  101. ),
  102. contentPadding: contentPadding,
  103. trailing: arrowRight5(),
  104. onTap: () {
  105. var device = Provider.of<Bluetooth>(context, listen: false)?.device;
  106. if(device != null){
  107. NavigatorUtil.goPage(context, (context) => DeviceScreen(device: device,));
  108. }
  109. },
  110. )
  111. ]).toList())),
  112. Padding(
  113. padding: labelPadding,
  114. child: Text("设备数据", style: Theme.of(context).textTheme.bodyText2),
  115. ),
  116. BoxWidget(
  117. paddingAll: false,
  118. body: ValueListenableBuilder(
  119. valueListenable: Provider.of<Bluetooth>(context, listen: false).dataNotifier,
  120. builder: (_, data, ___) => ListView(
  121. padding: EdgeInsets.all(0),
  122. physics: NeverScrollableScrollPhysics(),
  123. shrinkWrap: true,
  124. children: ListTile.divideTiles(context: context, tiles: [
  125. ListTile(
  126. title: Row(
  127. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  128. children: <Widget>[
  129. Text("设备电量"),
  130. Text(
  131. "${min(Converter.toInt(data['0_electricity']),Converter.toInt(data['1_electricity']))}%",
  132. style: Theme.of(context).textTheme.bodyText2,
  133. )
  134. ],
  135. ),
  136. contentPadding: contentPadding,
  137. onTap: () {
  138. Provider.of<Bluetooth>(context, listen: false).queryDeviceData();
  139. },
  140. ),
  141. ListTile(
  142. title: Row(
  143. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  144. children: <Widget>[
  145. Text("鞋内温度"),
  146. Text(
  147. "${data['0_temperature']??0}℃\t\t/\t\t${data['1_temperature']??0}℃",
  148. style: Theme.of(context).textTheme.bodyText2,
  149. )
  150. ],
  151. ),
  152. contentPadding: contentPadding,
  153. ),
  154. ListTile(
  155. title: Row(
  156. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  157. children: <Widget>[
  158. Text("压力指数"),
  159. Text(
  160. "${data['0_pressure']??0}\t\t/\t\t${data['1_pressure']??0}",
  161. style: Theme.of(context).textTheme.bodyText2,
  162. )
  163. ],
  164. ),
  165. contentPadding: contentPadding,
  166. ),
  167. ]).toList()))),
  168. Padding(
  169. padding: labelPadding,
  170. child: Text("基本信息", style: Theme.of(context).textTheme.bodyText2),
  171. ),
  172. BoxWidget(
  173. paddingAll: false,
  174. body: ValueListenableBuilder(
  175. valueListenable: Provider.of<Bluetooth>(context, listen: false).infoNotifier,
  176. builder: (_, data, ___) => ListView(
  177. padding: EdgeInsets.all(0),
  178. physics: NeverScrollableScrollPhysics(),
  179. shrinkWrap: true,
  180. children: ListTile.divideTiles(context: context, tiles: [
  181. ListTile(
  182. title: Row(
  183. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  184. children: <Widget>[
  185. Text("设备型号"),
  186. Text(
  187. "${data['name']??'SHOES'}",
  188. style: Theme.of(context).textTheme.bodyText2,
  189. )
  190. ],
  191. ),
  192. contentPadding: contentPadding,
  193. onTap: () {
  194. Provider.of<Bluetooth>(context, listen: false).queryDeviceInfo();
  195. },
  196. ),
  197. // ListTile(
  198. // title: Row(
  199. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  200. // children: <Widget>[
  201. // Text("鞋码"),
  202. // Text(
  203. // "42码",
  204. // style: Theme.of(context).textTheme.bodyText2,
  205. // )
  206. // ],
  207. // ),
  208. // contentPadding: contentPadding,
  209. // ),
  210. ListTile(
  211. title: Row(
  212. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  213. children: <Widget>[
  214. Text("软件版本"),
  215. Text(
  216. "V${data['softwareVer']??0}",
  217. style: Theme.of(context).textTheme.bodyText2,
  218. )
  219. ],
  220. ),
  221. contentPadding: contentPadding,
  222. ),
  223. ListTile(
  224. title: Row(
  225. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  226. children: <Widget>[
  227. Text("硬件版本"),
  228. Text(
  229. "V${data['hardwareVer']??0}",
  230. style: Theme.of(context).textTheme.bodyText2,
  231. )
  232. ],
  233. ),
  234. contentPadding: contentPadding,
  235. ),
  236. ListTile(
  237. title: Row(
  238. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  239. children: <Widget>[
  240. Text("蓝牙地址"),
  241. Text(
  242. "${Provider.of<Bluetooth>(context, listen: false)?.device?.id?.id ?? ""}",
  243. style: Theme.of(context).textTheme.bodyText2,
  244. )
  245. ],
  246. ),
  247. contentPadding: contentPadding,
  248. ),
  249. ]).toList()))),
  250. ]);
  251. }
  252. }