目前正在探索functional_widgets 和flutter_hooks。与 reactjs 有相同的想法,我正在使用以下代码获取数据。
@hwidget
Widget homeScreen(BuildContext context) {
TodoListProvider model = Provider.of<TodoListProvider>(context);
useEffect(() {
print('effect');
model.fetchList();
return () => {};
}, []);
return Scaffold(
appBar: _buildAppbar(context, model),
bottomNavigationBar: _buildBottomNav(context, model),
floatingActionButton: _buildFloatingAction(context),
body: PageTransitionSwitcher(
duration: const Duration(milliseconds: 300),
reverse: model.reverse,
transitionBuilder: (
Widget child,
Animation<double> animation,
Animation<double> secondaryAnimation,
) {
return SharedAxisTransition(
child: child,
animation: animation,
secondaryAnimation: secondaryAnimation,
transitionType: SharedAxisTransitionType.horizontal,
);
},
child: _getCurrentTab(model.currentIndex),
),
);
}