You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

425 lines
16 KiB

import 'dart:convert';
import 'package:doctor/patient_dashboard/BMI/bmi_caluculator.dart';
import 'package:flutter/material.dart';
import 'package:doctor/models/bmi_history_model.dart';
import 'package:doctor/common/settings.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
class BMIHistory extends StatefulWidget {
String? customerId;
BMIHistory({this.customerId});
@override
State<BMIHistory> createState() => _BMIHistoryState();
}
class _BMIHistoryState extends State<BMIHistory> {
bool isLoading = false;
List<BmiHistoryModel> bmiHistoryList = [];
List<BmiHistoryModel> FilteredList = [];
var dateItems = [
'All',
'last 7 days',
'last one month',
'last one year',
];
var dateItemsVariable = 'All';
Future<void> getBmiHistoryDetails(var selectedRange) async {
isLoading = true;
var response1 = await AppSettings.getBmiHistory(widget.customerId);
print(response1);
setState(() {
bmiHistoryList = ((jsonDecode(response1)) as List).map((dynamic model) {
return BmiHistoryModel.fromJson(model);
}).toList();
var now = new DateTime.now();
var now_1w = now.subtract(Duration(days: 7));
var now_1m = new DateTime(now.year, now.month - 1, now.day);
var now_1y = new DateTime(now.year - 1, now.month, now.day);
if (selectedRange.toString().toUpperCase() == 'LAST 7 DAYS') {
FilteredList = bmiHistoryList.where((product) {
final date = product.dateForFilter;
return now_1w.isBefore(date);
//reportsList=reportsListOriginal.reversed.toList();
}).toList();
}
else if (selectedRange.toString().toUpperCase() == 'LAST ONE MONTH') {
FilteredList = bmiHistoryList.where((product) {
final date = product.dateForFilter;
return now_1m.isBefore(date);
}).toList();
}
else if (selectedRange.toString().toUpperCase() == 'LAST ONE YEAR') {
FilteredList = bmiHistoryList.where((product) {
final date = product.dateForFilter;
return now_1y.isBefore(date);
}).toList();
}
else {
FilteredList = bmiHistoryList;
}
isLoading = false;
});
}
@override
void initState() {
getBmiHistoryDetails(dateItemsVariable);
super.initState();
}
deleteBmiHistory(bmiId) async{
AppSettings.preLoaderDialog(context);
bool status = await AppSettings.deleteBMIDetails(bmiId,widget.customerId);
if(status){
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longSuccessToast("BMI record deleted successfully");
await getBmiHistoryDetails(dateItemsVariable);
}
else{
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast("BMI record deletion failed");
}
}
Widget renderzUi() {
if (FilteredList.length != 0) {
FilteredList.sort((a, b) => a.actualDate.compareTo(b.actualDate));
return Column(crossAxisAlignment: CrossAxisAlignment.end, children: [
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: DropdownButtonFormField(
// Initial Value
value: dateItemsVariable,
isExpanded: true,
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.calendar_month,
color: primaryColor,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
labelText: 'Select Date Range',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
hint: Text('Units'),
// Down Arrow Icon
//icon: const Icon(Icons.keyboard_arrow_down),
// Array list of items
items: dateItems.map((String items) {
return DropdownMenuItem(
value: items,
child: Text(
items,
style: TextStyle(
fontSize: 16,
),
textAlign: TextAlign.center,
));
}).toList(),
// After selecting the desired option,it will
// change button value to selected value
onChanged: (String? newValue) {
setState(() {
dateItemsVariable = newValue!;
});
getBmiHistoryDetails(dateItemsVariable);
},
),
),
IconButton(
onPressed: () {
/*Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BmiChart()),
);*/
/*Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new BmiChart(myObject: FilteredList)));*/
// showBMIAdddialog();
},
icon: Icon(
Icons.auto_graph,
color: primaryColor,
),
),
Expanded(
child: ListView.builder(
padding: EdgeInsets.all(0),
itemCount: FilteredList.length,
itemBuilder: (BuildContext context, int index) {
return Slidable(
key: const ValueKey(0),
endActionPane: ActionPane(
// A motion is a widget used to control how the pane animates.
motion: ScrollMotion(),
dragDismissible: false,
// A pane can dismiss the Slidable.
dismissible: DismissiblePane(onDismissed: () {
deleteBmiHistory(FilteredList[index].bmiInfoId);
}),
// All actions are defined in the children parameter.
children: [
// A SlidableAction can have an icon and/or a label.
SlidableAction(
backgroundColor: Color(0xFFFE4A49),
foregroundColor: Colors.white,
icon: Icons.delete,
label: 'Delete',
onPressed: (BuildContext context) {
deleteBmiHistory(FilteredList[index].bmiInfoId);
},
),
/*SlidableAction(
onPressed: doNothing,
backgroundColor: Color(0xFF21B7CA),
foregroundColor: Colors.white,
icon: Icons.share,
label: 'Share',
),*/
],
),
child: Card(
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: MediaQuery.of(context).size.width * .55,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image(
image: const AssetImage(
'images/height.png'),
height: 25,
width: 25,
fit: BoxFit.fill),
Padding(
padding: EdgeInsets.all(5),
child: Text(
FilteredList[index]
.height
.toString()
.toUpperCase() +
' cms',
style: valuesTextStyle()),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image(
image: const AssetImage(
'images/weight.png'),
height: 25,
width: 25,
fit: BoxFit.fill),
Padding(
padding: EdgeInsets.all(5),
child: Text(
FilteredList[index]
.weight
.toString()
.toUpperCase() +
' Kgs',
style: valuesTextStyle()),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image(
image:
const AssetImage('images/date.png'),
height: 25,
width: 25,
fit: BoxFit.fill),
Padding(
padding: EdgeInsets.all(5),
child: Text(
FilteredList[index]
.actualDate
.toString()
.toUpperCase(),
style: valuesTextStyle()),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image(
image: const AssetImage(
'images/bmi.png'),
height: 25,
width: 25,
fit: BoxFit.fill),
Padding(
padding: EdgeInsets.all(5),
child: Text(
FilteredList[index]
.bmiValue
.toString()
.toUpperCase(),
style: valuesTextStyle()),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image(
image: const AssetImage(
'images/bmi.png'),
height: 25,
width: 25,
fit: BoxFit.fill),
Padding(
padding: EdgeInsets.all(5),
child: Text(
FilteredList[index].bmiText
.toString()
.toUpperCase(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,color: FilteredList[index].bmiTextColor
)),
)
],
),
],
),
),
],
),
),
),
);
})),
]);
}
else {
return Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * .25,
),
Text('No Data'),
SizedBox(
height: 20,
),
CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
Navigator.push(context, MaterialPageRoute(builder: (context) => BMICalculator(customerId:widget.customerId))).then((value) {
getBmiHistoryDetails(dateItemsVariable);
});
},
),
)
],
),
));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppSettings.appBar('Body Mass Index'),
body: isLoading
? Center(
child: CircularProgressIndicator(
color: primaryColor,
strokeWidth: 5.0,
),
)
: renderzUi(),
floatingActionButton: Visibility(
visible:FilteredList.length!=0,
child: CircleAvatar(
backgroundColor: buttonColors,
radius: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.black,
),
onPressed: () async {
Navigator.push(context, MaterialPageRoute(builder: (context) => BMICalculator(customerId: widget.customerId,))).then((value) {
getBmiHistoryDetails(dateItemsVariable);
});
},
),
/* Padding(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Text(
'Add Tanks ',
style: TextStyle(color: Colors.white),
),
)*/
],
),
),
),
);
}
}