【问题标题】:Page not moving to the next page页面没有移动到下一页
【发布时间】:2020-07-06 13:26:27
【问题描述】:

注册后我一直在尝试移动到另一个页面,但它没有移动到新页面。它只是将数据保存到数据库而不移动。它仍然在同一页面上。我需要它移动到另一个页面。

import 'package:flutter/material.dart';
import 'package:project_work/extra%20pages/screen/welcome.dart';
import 'LogIn.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'models.dart';

// had to switch the login part for sign up. So this page is Sign up.
class LogIn extends StatefulWidget {
  @override
  _LogInState createState() => new _LogInState();
}

class _LogInState extends State<LogIn> {
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  final _user = User();

  TextStyle style =
      TextStyle(fontFamily: '', fontSize: 20.0, color: Colors.black);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: new Stack(
      children: <Widget>[
        Column(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.only(left: 10.0),
            )
          ],
        ),
        Center(
            child: Container(
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage("assets/images/Artboardd.png"),
                    fit: BoxFit.cover,
                  ),
                ),
                alignment: Alignment.center,
                padding: const EdgeInsets.all(36.0),
                child: Builder(
                    builder: (context) => Form(
                        key: _formKey,
                        child: Column(

                            crossAxisAlignment: CrossAxisAlignment.stretch,
                            mainAxisAlignment: MainAxisAlignment.center,

                            children: [
                              SizedBox(height: 15.0),

                              Text(
                        "Register",
                        style: TextStyle(
                            color: Colors.black,
                            fontStyle: FontStyle.italic,
                            fontFamily: 'Pacifico',
                            fontSize: 50.0),
                            textAlign: TextAlign.center,
                              ),

                              TextFormField(
                                obscureText: false,
                                style: style,
                                keyboardType: TextInputType.emailAddress,
                                decoration: InputDecoration(
                                    labelText: 'Email',
                                    contentPadding: EdgeInsets.fromLTRB(
                                        20.0, 15.0, 20.0, 15.0),
                                    border: OutlineInputBorder(
                                        borderRadius:
                                            BorderRadius.circular(32.0)),
                                    icon: Icon(Icons.mail)),
                                validator: (value) {
                                  if (value.isEmpty) {
                                    return 'Please enter your Email';
                                  }
                                  return null;
                                },
                                onSaved: (val) =>
                                    setState(() => _user.email = val),
                              ),

                              SizedBox(height: 15.0),

                              TextFormField(
                                  obscureText: true,
                                  style: style,
                                  keyboardType: TextInputType.text,
                                  decoration: InputDecoration(
                                      labelText: 'Password',
                                      contentPadding: EdgeInsets.fromLTRB(
                                          20.0, 15.0, 20.0, 15.0),
                                      border: OutlineInputBorder(
                                          borderRadius:
                                              BorderRadius.circular(32.0)),
                                      icon: Icon(Icons.vpn_key)),
                                  validator: (value) {
                                    if (value.isEmpty || value.length < 6) {
                                      return 'Password must be at least 6 characters';
                                    }
                                    return null;
                                  },
                                  onSaved: (val) =>
                                      setState(() => _user.password = val)),
                              Container(
                                  padding: const EdgeInsets.symmetric(
                                      vertical: 16.0, horizontal: 16.0),
                                  child: RaisedButton(
                                 padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
                                      shape: RoundedRectangleBorder(
                                        borderRadius:
                                            new BorderRadius.circular(18.0),
                                        side: BorderSide(color: Colors.blue),
                                      ),
                                      color: Colors.blue,
                                      onPressed: signup,
                                      child: Text('Register'))),
                            ])))))
      ],
    ));
  } 

  _showDialog(BuildContext context) {
    Scaffold.of(context)
        .showSnackBar(SnackBar(content: Text('Registered Succesfully')));
  }

我无法判断此代码​​是否存在问题。你能帮忙吗

       void signup()async {
    if (_formKey.currentState.validate()) {
      _formKey.currentState.save();

      try {
        FirebaseUser user = (await FirebaseAuth.instance
            .createUserWithEmailAndPassword(
                email: _user.email, password: _user.password)) as FirebaseUser;
        user.sendEmailVerification();
        Navigator.pushReplacement(
            context, MaterialPageRoute(builder: (context)=> SignUp()));
      } catch (e) {
        print(e.messgae);
      }
    }
  }
}

【问题讨论】:

  • 这是什么方法user.sendEmailVerification();?它带你去哪里?
  • @PeterHaddad 应该向用户发送一封电子邮件以验证帐户,但我还没有为它编写代码

标签: firebase flutter dart firebase-authentication


【解决方案1】:

对我来说,它只需要使用:

 Navigator.push(context, MaterialPageRoute(builder: (context)=> Register(User: user,)));

希望对你有帮助!

【讨论】:

  • 我去看看
猜你喜欢
  • 2022-09-29
  • 1970-01-01
  • 2014-03-03
  • 1970-01-01
  • 1970-01-01
  • 2022-10-24
  • 2019-12-03
  • 2022-06-25
  • 2014-06-10
相关资源
最近更新 更多