Flutter,卡在登录上

标签 flutter

我尝试在登录后重定向到新屏幕

我正在编写一个应用程序,需要帮助更改显示的屏幕,当按下谷歌登录按钮时,它会验证配置文件,但我不知道如何让它在登录后转到主页,因此它只是重定向回登录页面并重复登录过程。我有什么办法可以解决这个问题吗?

import 'package:flutter/material.dart';
import 'auth.dart';
import 'flutter_auth_buttons.dart';



class LoginScreen2 extends StatelessWidget {
  final Color backgroundColor1;
  final Color backgroundColor2;
  final Color highlightColor;
  final Color foregroundColor;
  final AssetImage logo;

  LoginScreen2({Key k, this.backgroundColor1, this.backgroundColor2, this.highlightColor, this.foregroundColor, this.logo});

  @override
  Widget build(BuildContext context) {
   return Column(
        children: <Widget>[
          Container(
            decoration: new BoxDecoration(
              gradient: new LinearGradient(
                begin: Alignment.centerLeft,
                end: new Alignment(1.0, 0.0),
                // 10% of the width, so there are ten blinds.
                colors: [this.backgroundColor1, this.backgroundColor2],
                // whitish to gray
                tileMode: TileMode
                    .repeated, // repeats the gradient over the canvas
              ),
            ),
            height: MediaQuery
                .of(context)
                .size
                .height,
            child: Column(
              children: <Widget>[
                Container(
                  padding: const EdgeInsets.only(top: 150.0, bottom: 50.0),
                  child: Center(
                    child: new Column(
                      children: <Widget>[
                        Container(
                          height: 128.0,
                          width: 128.0,
                          child: new CircleAvatar(
                            backgroundColor: Colors.transparent,
                            foregroundColor: this.foregroundColor,
                            radius: 100.0,
                            child: new Text(
                              "",
                              style: TextStyle(
                                fontSize: 40.0,
                                fontWeight: FontWeight.w100,
                              ),
                            ),
                          ),

                        ),
                        new Padding(
                          padding: const EdgeInsets.all(16.0),

                        )
                      ],
                    ),
                  ),
                ),
                new Container(
                  width: MediaQuery
                      .of(context)
                      .size
                      .width,
                  margin: const EdgeInsets.only(left: 40.0, right: 40.0),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(

                  ),
                  padding: const EdgeInsets.only(left: 0.0, right: 10.0),
                  child: new Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,

                  ),
                ),
                new Container(
                  width: MediaQuery
                      .of(context)
                      .size
                      .width,
                  margin: const EdgeInsets.only(
                      left: 40.0, right: 40.0, top: 10.0),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                  ),
                  padding: const EdgeInsets.only(left: 0.0, right: 10.0),
                  child: new Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,

                  ),
                ),
                new Container(
                  width: MediaQuery
                      .of(context)
                      .size
                      .width,
                  margin: const EdgeInsets.only(
                      left: 40.0, right: 40.0, top: 30.0),
                  alignment: Alignment.center,
                  child: new Row(

                  ),
                ),

                new Container(
                  width: MediaQuery
                      .of(context)
                      .size
                      .width,
                  margin: const EdgeInsets.only(
                      left: 100.0, right: 40.0, top: 10.0),
                  alignment: Alignment.center,
                  child: new Row(
                    children: <Widget>[
                      GoogleSignInButton(onPressed: () =>authService.googleSignIn (
                       )) ,
                     new Expanded(
                        child: new FlatButton(
                          padding: const EdgeInsets.symmetric(
                              vertical: 20.0, horizontal: 20.0),
                          color: Colors.transparent,
                          onPressed: () => {},
                          child: Text(
                            "",
                            style: TextStyle(
                                color: this.foregroundColor.withOpacity(0.5)),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),

                new Expanded(child: Divider(),),

                new Container(
                  width: MediaQuery
                      .of(context)
                      .size
                      .width,
                  margin: const EdgeInsets.only(
                      left: 40.0, right: 40.0, top: 10.0, bottom: 20.0),
                  alignment: Alignment.center,
                  child: new Row(
                    children: <Widget>[
                      new Expanded(
                        child: new FlatButton(
                          padding: const EdgeInsets.symmetric(
                              vertical: 20.0, horizontal: 20.0),
                          color: Colors.transparent,
                          onPressed: () => {},
                          child: Text(
                            "Don't have an account? Create One",
                            style: TextStyle(
                                color: this.foregroundColor.withOpacity(0.5)),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          )
        ]);
  }}




  class SubPage extends StatelessWidget{
  @override
  Widget build(BuildContext context){
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Tile'),
      ),
      body: new GridView.count(
        crossAxisCount: 2,
        children: new List<Widget>.generate(1000, (index) {
          return new GridTile(
            child: new Card(
                color: Colors.blue.shade200,
                child: new Center(
                  child: new Text('tile $index'),
                )
            ),
          );
        }),
      ),
    );
  }
}

最佳答案

我假设谷歌登录按钮正在调用一个异步作业来验证用户信息并返回一个通知是否成功登录的 promise 。

在这种情况下,您可以在收到响应后导航到主页。

GoogleSignInButton(
 onPressed: () => authService.googleSignIn ().then((response){
  if(response is okay){
    Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
  }
 })
) 

关于Flutter,卡在登录上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56746976/

相关文章:

flutter : How can i create this circle avatar that's half out of the container?

firebase - 来自Firestore的数据未显示在 ListView 中

flutter - 第一次运行flutter 发现yaml文件报错: No pubspec.

reactjs - 在 react js 应用程序中使用 flutter web 小部件

flutter - BuildContext 在 Flutter 中做了什么?

firebase - Flutter:即使在屏幕之间导航后也会保存页面的状态

flutter - 如何在 flutter 中添加圆形评级图表?

flutter - 使用 flutter 动画显示或隐藏小部件

flutter | Dart : Target of URI does not exist

image - 视频文件到 flutter 中的图像流