From c83423bbc1ee3a74d7c571a7959e9baa23875e4d Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Sun, 3 Apr 2022 13:17:04 +0300 Subject: [PATCH] Fix the timer --- lib/home/first_column.dart | 32 +++++++ lib/home/home_screen.dart | 186 ++++++++++++++++++++++++------------ lib/home/que_item_list.dart | 24 +++-- pubspec.lock | 9 +- 4 files changed, 171 insertions(+), 80 deletions(-) create mode 100644 lib/home/first_column.dart diff --git a/lib/home/first_column.dart b/lib/home/first_column.dart new file mode 100644 index 0000000..23d24df --- /dev/null +++ b/lib/home/first_column.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; +import 'package:queuing_system/core/config/size_config.dart'; +import 'package:queuing_system/home/que_item/que_item.dart'; + +class FirstColumn extends StatelessWidget { + final bool have3Patient; + final bool have2Patient; + + const FirstColumn({Key key, this.have3Patient = false, this.have2Patient = false}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const QueItem(queNo: "OBG-T45", isFirstLine: true, isNurseVisit: true, haveListOfPatient: true,), + SizedBox( + height: SizeConfig.getHeightMultiplier() * 5,), + if(have3Patient ||have2Patient ) + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + if(have2Patient || have3Patient) + const QueItem(queNo: "OBG-T45", isSecondLine: true, isNurseVisit: false, haveListOfPatient: true,), + if(have3Patient) + const QueItem(queNo: "OBG-T45", isSecondLine: true, isNurseVisit: true, haveListOfPatient: true,), + ], + ), + ], + ); + } +} diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index 101a14d..566c383 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:queuing_system/core/base/app_scaffold_widget.dart'; import 'package:queuing_system/core/config/config.dart'; @@ -9,55 +11,144 @@ import 'package:queuing_system/utils/signalR_utils.dart'; import 'package:queuing_system/utils/utils.dart'; import 'package:queuing_system/widget/data_display/app_texts_widget.dart'; -class MyHomePage extends StatefulWidget { +import 'first_column.dart'; - String title ="MyHomePage"; - bool haveOnePatient = true; +class MyHomePage extends StatefulWidget { + String title = "MyHomePage"; + bool have0Patient = true; + bool have1Patient = false; + bool have2Patient = false; bool have3Patient = false; - bool haveListOfPatient = true; - + bool haveListOfPatient = false; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { + Timer _timer; + int remainingTime = 30; + + @override + void dispose() { + _timer.cancel(); + super.dispose(); + } + + startTimer() { + Timer.periodic(Duration(seconds: 1), (timer) { + if (remainingTime == 0) { + setState(() { + remainingTime = 30; + }); + } else { + setState(() { + remainingTime--; + if (remainingTime > 25) { + widget.have0Patient = true; + widget.have1Patient = false; + widget.have2Patient = false; + widget.have3Patient = false; + widget.haveListOfPatient = false; + } else if (remainingTime > 20) { + widget.have0Patient = false; + widget.have1Patient = true; + widget.have2Patient = false; + widget.have3Patient = false; + widget.haveListOfPatient = false; + } else if (remainingTime > 15) { + widget.have0Patient = false; + widget.have1Patient = false; + widget.have2Patient = true; + widget.have3Patient = false; + widget.haveListOfPatient = false; + } else if (remainingTime > 10) { + widget.have0Patient = false; + widget.have1Patient = false; + widget.have2Patient = false; + widget.have3Patient = true; + widget.haveListOfPatient = false; + } else if (remainingTime > 5) { + widget.have0Patient = false; + widget.have1Patient = false; + widget.have2Patient = false; + widget.have3Patient = true; + widget.haveListOfPatient = false; + } else { + widget.have0Patient = false; + widget.have1Patient = false; + widget.have2Patient = false; + widget.have3Patient = true; + widget.haveListOfPatient = true; + } + }); + } + }); + } + + @override + void initState() { + startTimer(); + super.initState(); + } + @override Widget build(BuildContext context) { - SignalRHelper signalRHelper= SignalRHelper(); + SignalRHelper signalRHelper = SignalRHelper(); return AppScaffold( appBar: AppHeader(), body: Column( children: [ - SizedBox(height: SizeConfig.getHeightMultiplier() * (widget.haveOnePatient?20: 2)), - widget.haveListOfPatient? - Row( - children: [ - FirstColumn( - have3Patient: widget.have3Patient, - ), - const SizedBox( - width: 40, - ), - if(widget.haveListOfPatient) - Container( - width: 10, - height:SizeConfig.getHeightMultiplier()*40, - color: AppGlobal.appLightGreyColor, - ), - if(widget.haveListOfPatient) - const SizedBox( - width: 40, - ), - if(widget.haveListOfPatient) - const QueItemList() - ], - ): FirstColumn(have3Patient: widget.have3Patient,), + SizedBox( + height: SizeConfig.getHeightMultiplier() * + (widget.haveListOfPatient + ? 2 + : widget.have1Patient || widget.have0Patient + ? 20 + : 10)), + widget.have0Patient + ? Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: AppText("Awaiting Patients Arrival", + fontFamily: 'Poppins-SemiBold.ttf', + fontSize: SizeConfig.getWidthMultiplier() * 9), + ), + ], + ) + : widget.haveListOfPatient + ? Row( + children: [ + FirstColumn( + have3Patient: widget.have3Patient, + have2Patient: widget.have2Patient, + ), + const SizedBox( + width: 40, + ), + if (widget.haveListOfPatient) + Container( + width: 10, + height: SizeConfig.getHeightMultiplier() * 40, + color: AppGlobal.appLightGreyColor, + ), + if (widget.haveListOfPatient) + const SizedBox( + width: 40, + ), + if (widget.haveListOfPatient) const QueItemList() + ], + ) + : FirstColumn( + have3Patient: widget.have3Patient, + have2Patient: widget.have2Patient, + ), ], ), bottomSheet: Container( color: Colors.transparent, - height: Utils.getHeight()* 0.9, + height: Utils.getHeight() * 0.9, width: double.infinity, child: Row( children: [ @@ -73,37 +164,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. - ); - } -} - -class FirstColumn extends StatelessWidget { - final bool have3Patient; - - const FirstColumn({Key key, this.have3Patient = false}) : super(key: key); - - @override - Widget build(BuildContext context) { - return Column( - mainAxisAlignment: MainAxisAlignment.start, - 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,), - ], - ), - ], + ), // This trailing comma makes auto-formatting nicer for build methods. ); } } diff --git a/lib/home/que_item_list.dart b/lib/home/que_item_list.dart index 4dea15c..4826085 100644 --- a/lib/home/que_item_list.dart +++ b/lib/home/que_item_list.dart @@ -7,20 +7,18 @@ class QueItemList extends StatelessWidget { @override Widget build(BuildContext context) { return SizedBox( - child: Expanded( - child: Column( - children: const [ - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), - QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), + child: Column( + children: const [ + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: false, haveListOfPatient: false,), + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: false, haveListOfPatient: false,), + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: true, haveListOfPatient: false,), + QueItem(queNo: "OBG-T45", isInListLine: true, isNurseVisit: false, haveListOfPatient: false,), - ],), - ), + ],), ); } } diff --git a/pubspec.lock b/pubspec.lock index 1f5e5a0..b88033d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -177,13 +177,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.11" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.2" meta: dependency: transitive description: @@ -307,7 +300,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.3" tuple: dependency: transitive description: