Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wycliffepeart/7f1bf66e73f86325a9237db0f04a827a to your computer and use it in GitHub Desktop.
Save wycliffepeart/7f1bf66e73f86325a9237db0f04a827a to your computer and use it in GitHub Desktop.
load more data in NestedScrollView with NotificationListener
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