|
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:healthcare_user/Sugar/sugar_history.dart';
|
|
|
|
import 'package:healthcare_user/common/settings.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class SugarCalculator extends StatefulWidget {
|
|
|
|
const SugarCalculator({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<SugarCalculator> createState() => _SugarCalculatorState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SugarCalculatorState extends State<SugarCalculator> {
|
|
|
|
|
|
|
|
TextEditingController fastingValueController = TextEditingController();
|
|
|
|
TextEditingController postParandialValueController = TextEditingController();
|
|
|
|
TextEditingController dateInput = TextEditingController();
|
|
|
|
String sugarValue = '';
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppSettings.appBar('Diabetes'),
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
child: Container(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
TextFormField(
|
|
|
|
cursorColor: greyColor,
|
|
|
|
controller: fastingValueController,
|
|
|
|
textCapitalization: TextCapitalization.characters,
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
prefixIcon: Icon(
|
|
|
|
Icons.person,
|
|
|
|
color: primaryColor,
|
|
|
|
),
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: primaryColor)),
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: primaryColor),
|
|
|
|
),
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: primaryColor),
|
|
|
|
),
|
|
|
|
labelText: 'Enter fasting sugar value',
|
|
|
|
labelStyle: TextStyle(
|
|
|
|
color: greyColor, //<-- SEE HERE
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 10),
|
|
|
|
TextFormField(
|
|
|
|
cursorColor: greyColor,
|
|
|
|
controller: postParandialValueController,
|
|
|
|
textCapitalization: TextCapitalization.characters,
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
prefixIcon: Icon(
|
|
|
|
Icons.person,
|
|
|
|
color: primaryColor,
|
|
|
|
),
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: primaryColor)),
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: primaryColor),
|
|
|
|
),
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: primaryColor),
|
|
|
|
),
|
|
|
|
labelText: 'Enter PostPrandial value',
|
|
|
|
labelStyle: TextStyle(
|
|
|
|
color: greyColor, //<-- SEE HERE
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 10),
|
|
|
|
SizedBox(height: 10),
|
|
|
|
Container(
|
|
|
|
child: TextFormField(
|
|
|
|
cursorColor: greyColor,
|
|
|
|
controller: dateInput,
|
|
|
|
decoration: textFormFieldDecorationBMI(
|
|
|
|
Icons.calendar_today, 'Enter Date'),
|
|
|
|
readOnly: true,
|
|
|
|
onTap: () async {
|
|
|
|
DateTime? pickedDate = await showDatePicker(
|
|
|
|
context: context,
|
|
|
|
initialDate: DateTime.now(),
|
|
|
|
firstDate: DateTime(1950),
|
|
|
|
lastDate: DateTime.now(),
|
|
|
|
builder: (BuildContext context, Widget? child) {
|
|
|
|
return Theme(
|
|
|
|
data: ThemeData.dark().copyWith(
|
|
|
|
colorScheme: ColorScheme.dark(
|
|
|
|
primary: buttonColors,
|
|
|
|
onPrimary: Colors.white,
|
|
|
|
surface: buttonColors,
|
|
|
|
onSurface: Colors.white,
|
|
|
|
),
|
|
|
|
dialogBackgroundColor: primaryColor,
|
|
|
|
),
|
|
|
|
child: child!,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (pickedDate != null) {
|
|
|
|
print(
|
|
|
|
pickedDate); //pickedDate output format => 2021-03-10 00:00:00.000
|
|
|
|
String formattedDate =
|
|
|
|
DateFormat('dd-MM-yyyy').format(pickedDate);
|
|
|
|
print(
|
|
|
|
formattedDate); //formatted date output using intl package => 2021-03-16
|
|
|
|
setState(() {
|
|
|
|
dateInput.text =
|
|
|
|
formattedDate; //set output date to TextField value.
|
|
|
|
});
|
|
|
|
} else {}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 10),
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height:
|
|
|
|
MediaQuery.of(context).size.height * .05,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: buttonColors, // background
|
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
if (fastingValueController.text != '' &&
|
|
|
|
postParandialValueController.text != ''&& dateInput.text!='') {
|
|
|
|
AppSettings.preLoaderDialog(context);
|
|
|
|
var payload = new Map<String, dynamic>();
|
|
|
|
|
|
|
|
payload["fasting"] = double.parse(fastingValueController.text.toString());
|
|
|
|
payload["postPrandial"] = double.parse(postParandialValueController.text.toString());
|
|
|
|
payload["date"] = dateInput.text.toString();
|
|
|
|
|
|
|
|
var value = await AppSettings.calculateSugar(payload);
|
|
|
|
var valueResponse = jsonDecode(value);
|
|
|
|
print(valueResponse);
|
|
|
|
setState(() {
|
|
|
|
sugarValue = valueResponse['userSugarDetails']['sugarCategory'].toString();
|
|
|
|
|
|
|
|
});
|
|
|
|
fastingValueController.clear();
|
|
|
|
postParandialValueController.clear();
|
|
|
|
dateInput.clear();
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
AppSettings.longFailedToast('Please enter valid details');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: const Text('Check Diabetes'),
|
|
|
|
)),
|
|
|
|
SizedBox(height: 10),
|
|
|
|
Container(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(sugarValue,style: TextStyle(color: Colors.red,fontWeight: FontWeight.bold,fontSize: 15),),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
),
|
|
|
|
SizedBox(height: 20),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => SugarHistory()),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
Icons.history,
|
|
|
|
color: primaryColor,
|
|
|
|
size: 40,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 10),
|
|
|
|
Padding(padding: EdgeInsets.fromLTRB(10,0,0,0),
|
|
|
|
child: Container(
|
|
|
|
child: Text('History',style:TextStyle(color:Colors.black,fontSize: 12,fontWeight: FontWeight.bold,)),
|
|
|
|
),)
|
|
|
|
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|