Added andesfit Spirometer
parent
0967e45752
commit
fd79b10f41
@ -0,0 +1,137 @@
|
||||
import 'package:diplomaticquarterapp/extensions/string_extensions.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:diplomaticquarterapp/pages/medical/my_trackers/my_trackers_view_model/my_trackers_view_model.dart';
|
||||
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
|
||||
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
|
||||
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class AndesFitSpirometerConnectScreen extends StatefulWidget {
|
||||
final BluetoothDevice deviceModel;
|
||||
|
||||
const AndesFitSpirometerConnectScreen({this.deviceModel});
|
||||
|
||||
@override
|
||||
State<AndesFitSpirometerConnectScreen> createState() => _AndesFitSpirometerConnectScreenState();
|
||||
}
|
||||
|
||||
class _AndesFitSpirometerConnectScreenState extends State<AndesFitSpirometerConnectScreen> {
|
||||
MyTrackersViewModel myTrackersVm;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
myTrackersVm = context.read<MyTrackersViewModel>();
|
||||
myTrackersVm.connectAndesfitSpirometerDevice(widget.deviceModel);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
myTrackersVm.valuePEF = null;
|
||||
myTrackersVm.valueFEV = null;
|
||||
myTrackersVm.isAndesfitDeviceConnected = null;
|
||||
myTrackersVm.disConnectAndesfitDevice(widget.deviceModel);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget buildSpirometerUI(MyTrackersViewModel myTrackersViewModel) {
|
||||
return Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
if ((myTrackersViewModel.valuePEF == null && myTrackersViewModel.valueFEV == null) && myTrackersViewModel.isAndesfitDeviceConnected) ...[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
mHeight(24.0),
|
||||
Column(
|
||||
children: [
|
||||
Text("Please blow gently", style: TextStyle(fontSize: 20)),
|
||||
],
|
||||
),
|
||||
mHeight(24.0),
|
||||
],
|
||||
),
|
||||
] else if ((myTrackersViewModel.valuePEF != null && myTrackersViewModel.valueFEV != null)) ...[
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
mHeight(24.0),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Text("PEF", style: TextStyle(fontSize: 20)),
|
||||
Text(myTrackersViewModel.valuePEF.toString(), style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold)),
|
||||
Text("", style: TextStyle(fontSize: 15)),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Text("FEV", style: TextStyle(fontSize: 20)),
|
||||
Text(myTrackersViewModel.valueFEV.toString(), style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold)),
|
||||
Text("", style: TextStyle(fontSize: 15)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
] else ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Some animation with the instruction",
|
||||
style: TextStyle(fontSize: 9.0),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppScaffold(
|
||||
appBarTitle: "${widget.deviceModel.localName}",
|
||||
showNewAppBar: true,
|
||||
isShowDecPage: false,
|
||||
showNewAppBarTitle: true,
|
||||
backgroundColor: Color(0xffF8F8F8),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Consumer(
|
||||
builder: (BuildContext context, MyTrackersViewModel myTrackersViewModel, Widget child) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
buildSpirometerUI(myTrackersViewModel),
|
||||
if (myTrackersViewModel.isAndesfitDeviceConnected != null && myTrackersViewModel.isAndesfitDeviceConnected) ...[
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DefaultButton(
|
||||
"Disconnect with ${widget.deviceModel.localName}",
|
||||
() async {
|
||||
myTrackersVm.disConnectAndesfitDevice(widget.deviceModel);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
textColor: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue