From db6d1a3a1f45ad740a048a10a8c4a212c64590aa Mon Sep 17 00:00:00 2001 From: yaso Date: Tue, 8 Oct 2024 10:09:58 +0200 Subject: [PATCH] add pull to refresh in layout builder (true or false option) --- .../mih_layout/mih_layout_builder.dart | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/Frontend/patient_manager/lib/mih_components/mih_layout/mih_layout_builder.dart b/Frontend/patient_manager/lib/mih_components/mih_layout/mih_layout_builder.dart index c82af8f8..2df54dd6 100644 --- a/Frontend/patient_manager/lib/mih_components/mih_layout/mih_layout_builder.dart +++ b/Frontend/patient_manager/lib/mih_components/mih_layout/mih_layout_builder.dart @@ -11,7 +11,8 @@ class MIHLayoutBuilder extends StatefulWidget { final MIHAppDrawer? actionDrawer; final Widget? secondaryActionDrawer; final Widget? bottomNavBar; - + final bool pullDownToRefresh; + final Future Function() onPullDown; //final String type; const MIHLayoutBuilder({ super.key, @@ -22,7 +23,8 @@ class MIHLayoutBuilder extends StatefulWidget { required this.actionDrawer, required this.secondaryActionDrawer, required this.bottomNavBar, - //required this.type, + required this.pullDownToRefresh, + required this.onPullDown, }); @override @@ -62,6 +64,43 @@ class _MIHLayoutBuilderState extends State { ); } + Widget getBody(double width, double height) { + if (widget.pullDownToRefresh == true) { + return RefreshIndicator( + onRefresh: widget.onPullDown, + child: SingleChildScrollView( + child: SafeArea( + child: SizedBox( + width: width, + height: height, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + getLayoutHeader(), + Expanded(child: widget.body), + ], + ), + ), + ), + ), + ); + } else { + return SafeArea( + child: SizedBox( + width: width, + height: height, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + getLayoutHeader(), + Expanded(child: widget.body), + ], + ), + ), + ); + } + } + @override void dispose() { super.dispose(); @@ -79,19 +118,7 @@ class _MIHLayoutBuilderState extends State { //drawerEnableOpenDragGesture: true, drawer: widget.actionDrawer, endDrawer: widget.secondaryActionDrawer, - body: SafeArea( - child: SizedBox( - width: screenSize.width, - height: screenSize.height, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - getLayoutHeader(), - Expanded(child: widget.body), - ], - ), - ), - ), + body: getBody(screenSize.width, screenSize.height), bottomNavigationBar: widget.bottomNavBar, ); }