Search posts, tags, users, and pages
there is still have a problem.
if a page have FutureBuilder in a inner TabBarView, it will reload while change bottomNavigationBar even thouth did AutomaticKeepAliveClientMixin.
I fix this, also set FutureBuilder's parent widget is PageView.
stackoverflow futurebuilder-reloading-whenever-the-bottomnavigationbaritem-is-changed
Hey Michael, Glad you found the solution for this. There's another one that might help. Here's the link.
sorry about that, my way found not work today!
the youtobe video the future property is no argument, but I need multi FutureBuilder with List.generate, I can't use it.
Expanded(
child: Container(
color: const Color(0xFFF0F0F0),
child: _homePageController == null
? Container()
: PageView(
onPageChanged: (pageIndex) {
},
physics: const ClampingScrollPhysics(),
controller: _homePageController,
children: List.generate(_homeRecommendDefaultCategoryList.length, (index) {
return FutureBuilder<dynamic>(
future: _homeRequestGoodsByRecommendCategory(index),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
I find a newer way to final fix this! change FutureBuilder code into a child StatefulWidget with AutomaticKeepAliveClientMixin, and wrap _homeRequestGoodsByRecommendCategory(index) to a fix property _requestFuture with a fix index.
that is PageView nested PageView all themself's children need AutomaticKeepAliveClientMixin. and FutureBuilder's future need a origin property.
children: List.generate(_homeRecommendDefaultCategoryList.length, (index) {
return HomeItemPage(
index: index,
homeRecommendDefaultCategoryList: _homeRecommendDefaultCategoryList,
homeTabBarThresholdNotifier: _homeTabBarThresholdNotifier);
}))))
and the HomeItemPage should be
class HomeItemPage extends StatefulWidget {
final int index;
final dynamic homeRecommendDefaultCategoryList;
final ValueNotifier<double> homeTabBarThresholdNotifier;
const HomeItemPage({Key? key, required this.index, required this.homeRecommendDefaultCategoryList, required this.homeTabBarThresholdNotifier})
: super(key: key);
@override
HomeItemPageState createState() => HomeItemPageState();
}
class HomeItemPageState extends State<HomeItemPage> with AutomaticKeepAliveClientMixin {
late Future _requestFuture;
@override
void initState() {
super.initState();
_requestFuture = _homeRequestGoodsByRecommendCategory();
print("--> homeItem initState");
}
@override
void dispose() {
print("--> homeItem dispose");
super.dispose();
}
@override
Widget build(BuildContext context) {
super.build(context);
print("--> homeItem build");
return FutureBuilder<dynamic>(
future: _requestFuture,
Michael Mao