From fdc8ef36ef5fce1af24102cabd399c59b25eb77b Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Thu, 1 Oct 2020 16:29:41 +0300 Subject: [PATCH] Refactor today page --- lib/config/config.dart | 2 +- .../AlHabibMedicalService/h2o/today_page.dart | 42 ++---- .../widgets/h20_floating_action_button.dart | 124 ++++-------------- 3 files changed, 35 insertions(+), 133 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index 34bd9363..02b58b34 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -248,7 +248,7 @@ const GET_PATIENT_ALLERGIES = 'Services/Patients.svc/REST/GetPatientAllergies'; // H2O -const H2O_GET_USER_PROGRESS = "/Services/H2ORemainder.svc/REST/H2O_GetUserProgress"; +const H2O_GET_USER_PROGRESS = "Services/H2ORemainder.svc/REST/H2O_GetUserProgress"; const H2O_INSERT_USER_ACTIVITY="Services/H2ORemainder.svc/REST/H2O_InsertUserActivity"; diff --git a/lib/pages/AlHabibMedicalService/h2o/today_page.dart b/lib/pages/AlHabibMedicalService/h2o/today_page.dart index 6ed1869d..55767e5a 100644 --- a/lib/pages/AlHabibMedicalService/h2o/today_page.dart +++ b/lib/pages/AlHabibMedicalService/h2o/today_page.dart @@ -6,28 +6,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:percent_indicator/circular_percent_indicator.dart'; - -class TodayPage extends StatefulWidget { - @override - _TodayPageState createState() => _TodayPageState(); -} - -class _TodayPageState extends State with TickerProviderStateMixin { - AnimationController _controller; - @override - void initState() { - _controller = new AnimationController( - vsync: this, - duration: const Duration(milliseconds: 500), - ); - super.initState(); - } - +class TodayPage extends StatelessWidget { @override Widget build(BuildContext context) { - - - return BaseView( + return BaseView( onModelReady: (model) => model.getUserProgressForTodayData(), builder: (_, model, widget) => AppScaffold( isShowAppBar: false, @@ -65,8 +47,8 @@ class _TodayPageState extends State with TickerProviderStateMixin { height: 4, ), Text(model.userProgressData ==null ?"0.0": - model.userProgressData.quantityConsumed - .toString() + 'ml', + model.userProgressData.quantityConsumed + .toString() + 'ml', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20.0, @@ -93,12 +75,12 @@ class _TodayPageState extends State with TickerProviderStateMixin { height: 4, ), Text(model.userProgressData ==null ?"0.0": - (model.userProgressData.quantityLimit - - model.userProgressData - .quantityConsumed) < 0 ? "0 ml" : - (model.userProgressData.quantityLimit - - model.userProgressData - .quantityConsumed).toString() + ' ml', + (model.userProgressData.quantityLimit - + model.userProgressData + .quantityConsumed) < 0 ? "0 ml" : + (model.userProgressData.quantityLimit - + model.userProgressData + .quantityConsumed).toString() + ' ml', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 18.0), @@ -174,11 +156,11 @@ class _TodayPageState extends State with TickerProviderStateMixin { ), ), floatingActionButton: H20FloatingActionButton( - controller: _controller, + // controller: _controller, model: model, ), ), ); - } } + diff --git a/lib/pages/AlHabibMedicalService/h2o/widgets/h20_floating_action_button.dart b/lib/pages/AlHabibMedicalService/h2o/widgets/h20_floating_action_button.dart index 782e6a00..a2fa1adf 100644 --- a/lib/pages/AlHabibMedicalService/h2o/widgets/h20_floating_action_button.dart +++ b/lib/pages/AlHabibMedicalService/h2o/widgets/h20_floating_action_button.dart @@ -11,114 +11,34 @@ import 'package:flutter/material.dart'; import '../add_custom_amount.dart'; -class H20FloatingActionButton extends StatelessWidget { +class H20FloatingActionButton extends StatefulWidget { const H20FloatingActionButton({ Key key, @required AnimationController controller, @required this.model - }) : _controller = controller, + }) : super(key: key); - final AnimationController _controller; final H2OViewModel model; + + @override + _H20FloatingActionButtonState createState() => _H20FloatingActionButtonState(); +} + +class _H20FloatingActionButtonState extends State with TickerProviderStateMixin { + AnimationController _controller; + @override + void initState() { + _controller = new AnimationController( + vsync: this, + duration: const Duration(milliseconds: 500), + ); + super.initState(); + } + @override Widget build(BuildContext context) { - // _showMaterialDialog(String count, H2OViewModel model) { - // return SimpleDialog( - // contentPadding: EdgeInsets.fromLTRB(28.0, 24.0, 28.0, 0.0), - // title: Center( - // child: Texts( - // "Confirm", - // color: Colors.black, - // ), - // ), - // children: [ - // Column( - // children: [ - // Divider(), - // Center( - // child: Texts( - // "Are you sure you want to Add $count ?", - // color: Colors.grey, - // ), - // ), - // SizedBox( - // height: 5.0, - // ), - // Row( - // // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // Expanded( - // flex: 1, - // child: InkWell( - // onTap: () { - // Navigator.pop(context); - // }, - // child: Padding( - // padding: const EdgeInsets.all(8.0), - // child: Container( - // child: Center( - // child: Texts( - // TranslationBase.of(context).cancel.toUpperCase(), - // color: Colors.red, - // ), - // ), - // ), - // ), - // ), - // ), - // Container( - // width: 1, - // height: 30, - // color: Colors.grey[500], - // ), - // Expanded( - // flex: 1, - // child: InkWell( - // onTap: () async{ - // // insertUserActivity - // int addedValue; - // - // switch(count) { - // case "600ml": { - // addedValue = 600; - // } - // break; - // - // case "330ml": { - // addedValue = 330; - // - // } - // break; - // case "200ml": { - // addedValue = 200; - // } - // break; - // - // } - // - // InsertUserActivityRequestModel insertUserActivityRequestModel= InsertUserActivityRequestModel(quantityIntake:addedValue ); - // await model.insertUserActivity(insertUserActivityRequestModel); - // Navigator.pop(context); - // }, - // child: Padding( - // padding: const EdgeInsets.all(8.0), - // child: Center( - // child: Texts( - // TranslationBase.of(context).ok, - // fontWeight: FontWeight.w400, - // )), - // ), - // ), - // ), - // ], - // ) - // ], - // ) - // ], - // ); - // } void showConfirmMessage(int amount, H2OViewModel model) { showDialog(context: context, child: ConfirmAddAmountDialog(model: model,amount:amount,)); @@ -137,21 +57,21 @@ class H20FloatingActionButton extends StatelessWidget { controller: _controller, text: "600ml", onTap: () { - showConfirmMessage(600, model); + showConfirmMessage(600, widget.model); }, ), ActionButton( controller: _controller, text: "330ml", onTap: () { - showConfirmMessage(330, model); + showConfirmMessage(330, widget.model); }, ), ActionButton( controller: _controller, text: "200ml", onTap: () { - showConfirmMessage(200, model); + showConfirmMessage(200, widget.model); }, ), ], @@ -205,7 +125,7 @@ class H20FloatingActionButton extends StatelessWidget { context, FadePage( page: AddCustomAmount( - model: model, + model: widget.model, ), ), );