From d0f67e88d96cdf615f1d3ee4b8bf105d30d85ca8 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Mon, 21 Mar 2022 12:56:17 +0300 Subject: [PATCH] add timer --- lib/home/home_screen.dart | 138 +++++++++++++++++++++++++++----------- 1 file changed, 97 insertions(+), 41 deletions(-) diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index 17e6afb..587e833 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -10,50 +10,87 @@ import 'package:queuing_system/utils/utils.dart'; import 'package:queuing_system/widget/data_display/app_texts_widget.dart'; class MyHomePage extends StatefulWidget { - - - String title ="MyHomePage"; + String title = "MyHomePage"; bool haveOnePatient = false; bool have3Patient = true; bool haveListOfPatient = false; - @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { + int remainingTime = 600; + + startTimer() { + this.remainingTime--; + if (remainingTime > 400) { + setState(() { + widget.haveOnePatient = true; + widget.have3Patient = false; + widget.haveListOfPatient = false; + }); + } else if (remainingTime > 200) { + setState(() { + widget.haveOnePatient = false; + widget.have3Patient = true; + widget.haveListOfPatient = false; + }); + } else { + setState(() { + widget.haveOnePatient = false; + widget.have3Patient = true; + widget.haveListOfPatient = true; + }); + } + + + Future.delayed(Duration(seconds: 1), () { + if (this.remainingTime > 0) { + startTimer(); + } else { + + } + + }); + } + @override Widget build(BuildContext context) { - SignalRHelper signalRHelper= SignalRHelper(); + SignalRHelper signalRHelper = SignalRHelper(); + startTimer(); return AppScaffold( appBar: AppHeader(), body: Column( children: [ - SizedBox(height: SizeConfig.getHeightMultiplier() * (widget.haveOnePatient?20: 3)), - widget.haveListOfPatient? - Row( - children: [ - FirstColumn( - have3Patient: widget.have3Patient, - ), - const SizedBox( - width: 40, - ), - if(widget.haveListOfPatient) - Container( - width: 10, - height:SizeConfig.getHeightMultiplier()*40, - color: Colors.grey, - ), - if(widget.haveListOfPatient) - const SizedBox( - width: 40, - ), - if(widget.haveListOfPatient) - const QueItemList() - ], - ): FirstColumn(have3Patient: widget.have3Patient,), + SizedBox( + height: SizeConfig.getHeightMultiplier() * + (widget.haveOnePatient ? 20 : 3)), + widget.haveListOfPatient + ? Row( + children: [ + FirstColumn( + have3Patient: widget.have3Patient, + ), + const SizedBox( + width: 40, + ), + if (widget.haveListOfPatient) + Container( + width: 10, + height: SizeConfig.getHeightMultiplier() * 40, + color: Colors.grey, + ), + if (widget.haveListOfPatient) + const SizedBox( + width: 40, + ), + if (widget.haveListOfPatient) const QueItemList() + ], + ) + : FirstColumn( + have3Patient: widget.have3Patient, + ), ], ), bottomSheet: Container( @@ -74,11 +111,14 @@ class _MyHomePageState extends State { ), Padding( padding: const EdgeInsets.only(top: 40, left: 18), - child: Image.asset( "assets/images/cloud_logo.png", height: SizeConfig.getHeightMultiplier()*5,), + child: Image.asset( + "assets/images/cloud_logo.png", + height: SizeConfig.getHeightMultiplier() * 5, + ), ), ], ), - ),// This trailing comma makes auto-formatting nicer for build methods. + ), // This trailing comma makes auto-formatting nicer for build methods. ); } } @@ -92,18 +132,34 @@ class FirstColumn extends StatelessWidget { Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.start, - children: [ - const QueItem(queNo: "OBG-T45", isFirstLine: true, isNurseVisit: true, haveListOfPatient: true,), + children: [ + const QueItem( + queNo: "OBG-T45", + isFirstLine: true, + isNurseVisit: true, + haveListOfPatient: true, + ), SizedBox( - height: SizeConfig.getHeightMultiplier() * 5,), - if(have3Patient) - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: const [ - QueItem(queNo: "OBG-T45", isSecondLine: true, isNurseVisit: true, haveListOfPatient: true,), - QueItem(queNo: "OBG-T45", isSecondLine: true, isNurseVisit: false, haveListOfPatient: true,), - ], + height: SizeConfig.getHeightMultiplier() * 5, ), + if (have3Patient) + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: const [ + QueItem( + queNo: "OBG-T45", + isSecondLine: true, + isNurseVisit: true, + haveListOfPatient: true, + ), + QueItem( + queNo: "OBG-T45", + isSecondLine: true, + isNurseVisit: false, + haveListOfPatient: true, + ), + ], + ), ], ); }