返回

flutter-我需要我的应用程序以欢迎屏幕而不是登录屏幕开始

发布时间:2022-03-18 12:40:51 635

我对Flatter是新手,在我的新项目中,我创建了一个欢迎屏幕,它有两个按钮:登录或注册,我使用一个包装器进行身份验证,并在登录和注册之间切换。。。每件事都很好,但一旦应用午餐,它就会显示登录屏幕,而不是欢迎屏幕!

这是我的包装课程

class wrapper extends StatelessWidget {
  const wrapper({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    final userModel = Provider.of(context);

    // either home or login page
    if(userModel == null){
      return const Authenticate();
    }else{
      return const Home();
    }
  }
}

这是我的主要观点

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return StreamProvider.value(
      initialData: null,
      value: Authentication().onAuthStateChanged,
        builder: (context, snapshot) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          title: 'Flutter Auth',
          theme: ThemeData(
            primaryColor: kPrimaryColor,
            scaffoldBackgroundColor: Colors.white,
            textTheme: GoogleFonts.nunitoTextTheme(),
          ),
          home: wrapper(),
        );
      }
    );
  }
}

身份验证类:

class Authenticate extends StatefulWidget {
  const Authenticate({Key? key}) : super(key: key);

  @override
  _AuthenticateState createState() => _AuthenticateState();
}

class _AuthenticateState extends State {
  bool showSignIn = true ;
  void toggleView() {
    setState(() {
      showSignIn = !showSignIn;
    });
  }
  @override
  Widget build(BuildContext context) {
    if(showSignIn){
      return LoginScreen(toggleView : toggleView);
    }else{
      return SignUpScreen(toggleView : toggleView);
    }

  }
}

欢迎屏幕:

class WelcomeScreen extends StatelessWidget {
  const WelcomeScreen({Key? key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Body(),
    );
  }
}

正文:

class Body extends StatelessWidget {
  const Body({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return Container(
      height: size.height,
      width: double.infinity,
      color: Color(0xFFA9D7CC),
      child:Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          SizedBox(width: size.width,height: 70),
          SvgPicture.asset(
              "assets/images/recycle.svg" ,
              width:441.4,
              height: 294 ,
          ),
          const Padding(
              padding: EdgeInsets.fromLTRB(20, 40, 7, 0),
            child:
            Text("lets make saving the planet easy !",
              style: TextStyle(
                  fontSize: 48 ,
                  fontWeight: FontWeight.bold,
                  color: Colors.white
              ),
            ),
          ),

           const Padding(
            padding: EdgeInsets.fromLTRB(27, 10, 110, 0),
            child:
            Text("start recycling and earn some money ",
              style: TextStyle(
                  fontSize: 20 ,
                  fontWeight: FontWeight.normal,
                  color: Colors.white
              ),
            ),
          ),

      SizedBox(width: size.width,height: 70),

      // login button
      SizedBox(
        width: 297,
        height: 71,
        child: ElevatedButton(
          style:ElevatedButton.styleFrom(
            primary: kPrimaryPopColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(40)
            )
          ) ,
            onPressed: (){},
            child: const Text("login",
              style: TextStyle(
                  color: Colors.white,
                fontSize: 24,
                fontWeight: FontWeight.bold
              ),)),
      ),

          //sign up button
          SizedBox(
            height: 70,
            child: TextButton(
              style: ButtonStyle(
                foregroundColor: MaterialStateProperty.all(Colors.white),
              ),
              onPressed: () {},
              child: const Text('sign up',
              style: TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),),
            ),
          )

        ],
        
      ),
    );
  }
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
相关帖子