add pull to refresh in layout builder (true or false option)

This commit is contained in:
2024-10-08 10:09:58 +02:00
parent 3027d3bb39
commit db6d1a3a1f

View File

@@ -11,7 +11,8 @@ class MIHLayoutBuilder extends StatefulWidget {
final MIHAppDrawer? actionDrawer; final MIHAppDrawer? actionDrawer;
final Widget? secondaryActionDrawer; final Widget? secondaryActionDrawer;
final Widget? bottomNavBar; final Widget? bottomNavBar;
final bool pullDownToRefresh;
final Future<void> Function() onPullDown;
//final String type; //final String type;
const MIHLayoutBuilder({ const MIHLayoutBuilder({
super.key, super.key,
@@ -22,7 +23,8 @@ class MIHLayoutBuilder extends StatefulWidget {
required this.actionDrawer, required this.actionDrawer,
required this.secondaryActionDrawer, required this.secondaryActionDrawer,
required this.bottomNavBar, required this.bottomNavBar,
//required this.type, required this.pullDownToRefresh,
required this.onPullDown,
}); });
@override @override
@@ -62,6 +64,43 @@ class _MIHLayoutBuilderState extends State<MIHLayoutBuilder> {
); );
} }
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 @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
@@ -79,19 +118,7 @@ class _MIHLayoutBuilderState extends State<MIHLayoutBuilder> {
//drawerEnableOpenDragGesture: true, //drawerEnableOpenDragGesture: true,
drawer: widget.actionDrawer, drawer: widget.actionDrawer,
endDrawer: widget.secondaryActionDrawer, endDrawer: widget.secondaryActionDrawer,
body: SafeArea( body: getBody(screenSize.width, screenSize.height),
child: SizedBox(
width: screenSize.width,
height: screenSize.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
getLayoutHeader(),
Expanded(child: widget.body),
],
),
),
),
bottomNavigationBar: widget.bottomNavBar, bottomNavigationBar: widget.bottomNavBar,
); );
} }