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
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.