Flutter 在登录和;仪表板屏幕?

Flutter 在登录和;仪表板屏幕?,flutter,authentication,Flutter,Authentication,我对flatter是个新手,我想检查用户在启动应用程序时是否登录。如果他这样做了,他会自动进入仪表板屏幕,如果没有,他会进入登录屏幕 我的问题是,在他连接/断开连接时,我没有导航动画 所以我想知道是否还有其他方法可以做到这一点,尤其是当登录屏幕没有底部导航栏时 顺便说一句,我使用Provider包作为状态管理,使用PersistentBottomNavBar作为导航 这是我的密码: main.dart: class MyApp extends StatelessWidget { @overr

我对flatter是个新手,我想检查用户在启动应用程序时是否登录。如果他这样做了,他会自动进入仪表板屏幕,如果没有,他会进入登录屏幕

我的问题是,在他连接/断开连接时,我没有导航动画

所以我想知道是否还有其他方法可以做到这一点,尤其是当登录屏幕没有底部导航栏时

顺便说一句,我使用
Provider
包作为状态管理,使用
PersistentBottomNavBar
作为导航

这是我的密码:

main.dart:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'My App',
        home: context.watch<AuthProvider>().isLoggued ? MainMenu() : LoginPage(),
    );
  }
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“我的应用程序”,
主页:context.watch().isLoggued?主菜单():登录页面(),
);
}
}
主菜单.省道

class MainMenu extends StatefulWidget {
  @override
  _MainMenuState createState() => _MainMenuState();
}

class _MainMenuState extends State<MainMenu> {
  PersistentTabController _controller = PersistentTabController(initialIndex: 0);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PersistentTabView(
        context,
        controller: _controller,
        screens: _buildScreens(),
        items: _navBarsItems(),
        ...
      ),
    );
  }

  List<Widget> _buildScreens() {
    return [
      DashboardPage(),
      MessagesPage(),
      ProfilePage(),
    ];
  }

  List<PersistentBottomNavBarItem> _navBarsItems() {
    return [
      PersistentBottomNavBarItem(
        icon: Icon(CupertinoIcons.home),
        activeColorPrimary: Theme.of(context).primaryColor,
        inactiveColorPrimary: CustomColors.backgroundPrimaryGray,
        routeAndNavigatorSettings: RouteAndNavigatorSettings(
          initialRoute: DashboardPage.routeName,
          routes: {
            LoginPage.routeName: (ctx) => LoginPage(),
            DashboardPage.routeName: (ctx) => DashboardPage(),
          },
        ),
      ),
      PersistentBottomNavBarItem(
        icon: Icon(CupertinoIcons.bubble_left),
        activeColorPrimary: Theme.of(context).primaryColor,
        inactiveColorPrimary: CustomColors.backgroundPrimaryGray,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(CupertinoIcons.person),
        activeColorPrimary: Theme.of(context).primaryColor,
        inactiveColorPrimary: CustomColors.backgroundPrimaryGray,
      ),
    ];
  }
}
class主菜单扩展StatefulWidget{
@凌驾
_MainMenuState createState()=>U MainMenuState();
}
类_main自定义扩展状态{
PersistentTabController _controller=PersistentTabController(初始索引:0);
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:PersistentTabView(
上下文
控制器:_控制器,
屏幕:_buildScreens(),
项目:_navBarsItems(),
...
),
);
}
列表_buildScreens(){
返回[
仪表板页(),
MessagesPage(),
ProfilePage(),
];
}
列表_navBarsItems(){
返回[
持续底部气压计(
图标:图标(CupertinoIcons.home),
activeColorPrimary:Theme.of(context).primaryColor,
inactiveColorPrimary:CustomColor.backgroundPrimaryGray,
RouteAndNavigator设置:RouteAndNavigator设置(
initialRoute:DashboardPage.routeName,
路线:{
LoginPage.routeName:(ctx)=>LoginPage(),
DashboardPage.routeName:(ctx)=>DashboardPage(),
},
),
),
持续底部气压计(
图标:图标(CupertinoIcons.bubble_左),
activeColorPrimary:Theme.of(context).primaryColor,
inactiveColorPrimary:CustomColor.backgroundPrimaryGray,
),
持续底部气压计(
图标:图标(CupertinoIcons.person),
activeColorPrimary:Theme.of(context).primaryColor,
inactiveColorPrimary:CustomColor.backgroundPrimaryGray,
),
];
}
}

谢谢你的帮助

> P>如果在Login页面和主页之间切换时需要动画,请考虑将AnimatedSwitcher用作ObjalApp的子节点,如果您的提供程序更改ISLogGoDIN值:

,它将动画化。
如果两个子小部件都有相同的键,则这不起作用,因此请确保通过为两个小部件提供不同值的键参数来指定不同的小部件(即其中一个为ValueKey(1),另一个为ValueKey(2)

好吧,您的想法似乎可行,但我遇到了一个问题,即
上下文。watch
只能以一种方式工作(当我注销时)。如果我登录,屏幕不会刷新,但在我注销时会刷新。如果你知道为什么。。。这就是我现在要做的:
child:context.watch().isLoggued?主菜单(键:ValueKey(1)):选择LoginTypePage(键:ValueKey(2))
登录时是否正在调用notifylisteners()?是。我最终替换了
context。通过
context查看
。阅读
并调用
Navigator。手动按下并移动直到
。对我来说这不是最好的解决办法,但它确实起到了作用。