Last active
October 4, 2024 13:05
-
-
Save IkhwanSI13/eb09a588096db4c88f96ad9f2faf91d1 to your computer and use it in GitHub Desktop.
load more data in NestedScrollView with NotificationListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cartenz_djp/style/colors.dart'; | |
import 'package:cartenz_djp/widget/override/customTabs.dart' as Tabs; | |
import 'package:flutter/material.dart'; | |
class ExampleWidget extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() => ExampleState(); | |
} | |
class ExampleState extends State<ExampleWidget> { | |
onLoadMore() { | |
//Load More, do something | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: ColorWhite, | |
body: Column( | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: <Widget>[ | |
Expanded( | |
child: Builder(builder: (BuildContext context) { | |
return NestedScrollView( | |
//controller: scrollController, | |
headerSliverBuilder: | |
(BuildContext context, bool innerBoxIsScrolled) { | |
return <Widget>[ | |
SliverAppBar( | |
bottom: getTabHeader(), | |
) | |
]; | |
}, body: Builder(builder: (BuildContext context) { | |
return Stack(children: <Widget>[ | |
getTabBody(), | |
]); | |
})); | |
}), | |
) | |
], | |
), | |
); | |
} | |
Widget getTabHeader() { | |
return Tabs.TabBar(tabs: [ | |
Tabs.Tab(child: Text("Tab 1")), | |
Tabs.Tab(child: Text("Tab 2")), | |
Tabs.Tab(child: Text("Tab 3")), | |
]); | |
} | |
Widget getTabBody() { | |
return Column( | |
children: <Widget>[ | |
Expanded( | |
child: Tabs.TabBarView(children: [ | |
Container( | |
child: | |
//Solved with this | |
NotificationListener<ScrollNotification>( | |
child: MediaQuery.removePadding( | |
context: context, | |
removeTop: true, | |
child: ListView.builder( | |
shrinkWrap: true, | |
itemCount: 3, | |
physics: NeverScrollableScrollPhysics(), | |
itemBuilder: (BuildContext context, int index) { | |
return Container(); | |
})), | |
onNotification: (ScrollNotification scrollInfo) { | |
if (scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) { | |
//load more here | |
onLoadMore(); | |
} | |
return false; | |
}, | |
); | |
Container(child: Container()), | |
Container(child: Container()) | |
])) | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code.It is working well 👍