[英]Flutter Page View dispose children, how to keep children and bloc
I have the next structure of code and any time when I swipe to the next page, pageview distroy previos page(widget and bloc)我有下一个代码结构,每当我滑动到下一页时,pageview distroy previos page(widget and bloc)
home: SafeArea( child: PageView(controller: _pageController, children: [ Scaffold( body: BlocProvider<Bloc>( bloc: bloc, child: Container()), Scaffold( body: BlocProvider<Bloc>( bloc: bloc, child: Container()) Scaffold( body: BlocProvider<Bloc>( bloc: bloc, child: Container())))
How can I save bloc class with a widget when pageview changes pages? home: SafeArea( child: PageView(controller: _pageController, children: [ Scaffold( body: BlocProvider<Bloc>( bloc: bloc, child: Container()), Scaffold( body: BlocProvider<Bloc>( bloc: bloc, child: Container()) Scaffold( body: BlocProvider<Bloc>( bloc: bloc, child: Container())))
pageview 换页时如何用widget保存bloc class?
children of PageView need is a StatefullWidget and State of StatefullWidget is add with AutomaticKeepAliveClientMixin PageView的子级需要一个StatefullWidget , StatefullWidget的 State 是用 AutomaticKeepAliveClientMixin添加的
Example :示例:
class _SearchPageState extends State<SearchPage>
with AutomaticKeepAliveClientMixin {
static const TAG = 'SearchPage';
VoidCallback onTapSort, onTapArea, onTapDatePicker, onTapFilter;
SearchPageFilter searchFilter;
WorkBloc _workBloc;
VoidCallback onReloadPage;
@override
void initState() {
super.initState();
@override
Widget build(BuildContext context) {
super.build(context);
return ChangeNotifierProvider.value(
value: searchFilter,
child: Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context).titleSearchPage),
bottom: PreferredSize(
child: SearchSliverPersistentHeaderDelegate(
onTapSort, onTapArea,
onTapDatePicker: onTapDatePicker,
onTapFilter: onTapFilter),
preferredSize: Size.fromHeight(128)),
),
body: Builder(
builder: (context) {
//.....
}
),
),
);
}
@override
bool get wantKeepAlive => true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.