Flutter 如何在flatter main.dart中合并两个主功能
我期待有一个应用程序与侧栏导航,也验证用户启动应用程序。侧边栏功能确保使用导航状态在应用程序的每个页面上进行侧边导航,新的根页面确保用户通过身份验证才能使用应用程序。这两个函数需要使用home:函数,并且不能在main.dart文件中包含这两个函数。有什么想法我可以把两者结合起来吗Flutter 如何在flatter main.dart中合并两个主功能,flutter,Flutter,我期待有一个应用程序与侧栏导航,也验证用户启动应用程序。侧边栏功能确保使用导航状态在应用程序的每个页面上进行侧边导航,新的根页面确保用户通过身份验证才能使用应用程序。这两个函数需要使用home:函数,并且不能在main.dart文件中包含这两个函数。有什么想法我可以把两者结合起来吗 import 'package:flutter/material.dart'; import 'services/authentication.dart'; //authentication module impor
import 'package:flutter/material.dart';
import 'services/authentication.dart'; //authentication module
import 'sidebar/sidebar_layout.dart'; sidebar navigation
import 'pages/root_page.dart'; //page that looks if user has an id
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'M-Afya',
theme: ThemeData(
scaffoldBackgroundColor: Colors.white,
primaryColor: Colors.white,
),
home: new RootPage(auth: new Auth()) //ensures one must be authenticated to use the application
home: SideBarLayout() //sidebar navigation
);
}
}
如何做到这一点?如果您将MyApp作为一个有状态的小部件,然后您可以检查initState(),如果用户通过身份验证,如果不执行以下操作,那么您可以检查initState(),但我没有得到SideBarLayout()在家中的含义(您使用它的目的是什么)。请你详细说明一下好吗
让我知道它是否有效。这里有一个视频,可以帮助您在lgoin和主页+状态初始化之间切换,您可以相应地添加侧栏 基于您的描述和代码,很难理解您想要做什么。尝试澄清您的问题。侧边栏布局为应用程序中的所有页面提供了一个自定义的抽屉