我有一个TabBarView3 TabBar。当我在选项卡 1 中时我做了一些事情,然后当我回到选项卡 1 时导航到选项卡 2 我希望选项卡 1 的先前状态不会改变。
我如何在 Flutter 中实现这一点?
下面是我的代码截图
class _LandingPageState extends State<LandingPage> with SingleTickerProviderStateMixin {
int _selectedIndex = 0;
PageController pageController;
TabController tabController;
@override
void initState() {
tabController = TabController(length: 3, vsync: this, initialIndex: 0);
pageController = PageController(initialPage: 0)
..addListener(() {
setState(() {
_selectedIndex = pageController.page.floor();
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
onTap: (index) {
setState(() {
_selectedIndex = index;
tabController.animateTo(index,
duration: …Run Code Online (Sandbox Code Playgroud) 是否可以在观察者内部使用协同程序来更新 UI?
例如:
Viewmodel.data.observer(this, Observer{ coroutinescope })
Run Code Online (Sandbox Code Playgroud) android kotlin android-architecture-components kotlin-coroutines