123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- import 'package:flutter/material.dart';
- import 'dart:async';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- import 'package:vnote_device_plugin/models/device.dart';
- import 'package:vnote_device_plugin/vnote_device_plugin.dart';
- import 'package:vnote_device_plugin_example/search.dart';
- import 'package:vnote_device_plugin_example/sp_o2.dart';
- import 'package:vnote_device_plugin_example/sugar.dart';
- import 'package:vnote_device_plugin_example/twelve_heart.dart';
- import 'package:vnote_device_plugin_example/urine.dart';
- import 'package:vnote_device_plugin_example/weight_height.dart';
- import 'package:vnote_device_plugin_example/widgets/demo.dart';
- import 'device.dart';
- import 'global.dart';
- import 'heart.dart';
- import 'ic_reader.dart';
- import 'nibp.dart';
- import 'temp.dart';
- import 'weight.dart';
- void main() {
- runApp(const MyApp());
- }
- class MyApp extends StatefulWidget {
- const MyApp({super.key});
- @override
- State<MyApp> createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- String _platformVersion = 'Unknown';
- DeviceInfo? _deviceInfo;
- final _vnoteDevicePlugin = VnoteDevicePlugin();
- static const List<String> _typeValues = [
- "temp",
- "weight",
- "sugar",
- "spo2",
- "nibp",
- "heart",
- "urine",
- "ic_reader",
- "twelveheart",
- "weight_height",
- ];
- static const List<String> _typeNames = [
- "体温",
- "体重",
- "血糖",
- "血氧",
- "血压",
- "心电",
- "尿液",
- "人证",
- "12导心电",
- "身高体重",
- ];
- int _typeIndex = 0;
- @override
- void initState() {
- super.initState();
- initPlatformState();
- }
- Future<void> initPlatformState() async {
- String platformVersion;
- try {
- platformVersion = await _vnoteDevicePlugin.getPlatformVersion() ??
- 'Unknown platform version';
- await Global.init();
- } on PlatformException {
- platformVersion = 'Failed to get platform version.';
- }
- if (!mounted) return;
- setState(() {
- _platformVersion = platformVersion;
- });
- }
- @override
- Widget build(BuildContext context) {
- return GetMaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: const Text('Plugin example app'),
- actions: [
- IconButton(
- onPressed: () async {
- // VnoteDevicePluginPlatform.instance.callAction(
- // "SEARCH_STOP",
- // {
- // "TYPE": "temp",
- // },
- // );
- Get.put<DevicesSettingController>(DevicesSettingController());
- await Get.to(() => const DevicesSettingPage());
- Get.delete<DevicesSettingController>();
- },
- icon: const Icon(Icons.stop),
- ),
- ],
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- // Text('Running on: $_platformVersion\n'),
- _buildTypeSelect(),
- const SizedBox(height: 8),
- DeviceCard(data: _deviceInfo),
- if (_deviceInfo != null) ...[
- const SizedBox(height: 8),
- _buildExamCard(),
- ],
- ],
- ),
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () async {
- final result = await SearchDialog.dialog(_typeValues[_typeIndex]);
- if (result != null) {
- setState(() {
- _deviceInfo = result;
- });
- } else {
- //
- }
- },
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: const [
- Icon(Icons.search),
- Text(
- "搜索",
- style: TextStyle(fontSize: 12),
- ),
- ],
- ),
- ),
- ),
- );
- }
- Widget _buildTypeSelect() {
- final items = <DropdownMenuItem<int>>[];
- for (var i = 0; i < _typeValues.length; i++) {
- items.add(
- DropdownMenuItem<int>(
- value: i,
- child: Text(_typeNames[i]),
- ),
- );
- }
- selectedBuilder(BuildContext context) {
- final widgets = <Widget>[];
- for (var i = 0; i < _typeValues.length; i++) {
- TextStyle? style;
- if (i == _typeIndex) {
- style = TextStyle(
- color: Theme.of(context).primaryColor,
- fontWeight: FontWeight.bold,
- );
- }
- widgets.add(Text(_typeNames[i], style: style));
- }
- return widgets;
- }
- return Container(
- alignment: Alignment.center,
- // width: 120,
- height: 30,
- // decoration: BoxDecoration(
- // border: Border.all(),
- // borderRadius: BorderRadius.circular(8),
- // ),
- child: DropdownButton<int>(
- // underline: SizedBox(),
- items: items,
- value: _typeIndex,
- selectedItemBuilder: selectedBuilder,
- onChanged: (index) {
- if (index != null) {
- setState(() {
- _typeIndex = index;
- _deviceInfo = null;
- });
- }
- },
- ),
- );
- }
- Widget _buildExamCard() {
- final type = _typeValues[_typeIndex];
- switch (type) {
- case "temp":
- return TempCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "weight":
- return WeightCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "sugar":
- return SugarCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "spo2":
- return SpO2Card(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "nibp":
- return NibpCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "heart":
- return HeartCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "urine":
- return UrineCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "ic_reader":
- return ICReaderCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "twelveheart":
- return TwelveHeartCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- case "weight_height":
- return WeightHeightCard(
- mac: _deviceInfo!.mac,
- model: _deviceInfo!.model,
- );
- default:
- return const SizedBox();
- }
- }
- }
|