Navigator.push ()를 사용하여 이메일 및 비밀번호로 로그인하여 Flutter의 다른 창에 액세스 할 수 없습니다.

Chorche

홈 로그인 창에서 접속하고 싶은데 기존 계정으로 로그인을 시도하면 버튼이 작동하지 않고 창이 그대로 유지됩니다.

import 'package:finalproject/Pages/home.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';

class LoginPage extends StatefulWidget {
  @override
  _LoginPageState createState() => new _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  String _email, _password; 

 @override
 Widget build(BuildContext context) {
return new Scaffold(
  appBar: new AppBar(
    title: Text('Sign in'),
  ),
  body: Form(
    key: _formKey, 
    child: Column(
      children: <Widget>[

        TextFormField(
          validator: (input) {
            if (input.isEmpty) {
              return '  Write your email';
            }
            return null;
          },
          onSaved: (input) => _email = input,
          decoration: InputDecoration(labelText: '  Email'),
        ),

        TextFormField(
          validator: (input) {
            if (input.length < 6) {
              return '  Write your password';
            }
            return null;
          },
          onSaved: (input) => _password = input,
          decoration: InputDecoration(labelText: '  Password'),
          obscureText: true,
        ),

        RaisedButton(
          onPressed: signIn,
          child: Text('Sign in'),
        ),],),),);}


void signIn() async {

if (_formKey.currentState.validate()) {
  _formKey.currentState.save();
  try {
    // ignore: deprecated_member_use
    UserCredential authResult = await FirebaseAuth.instance
        .signInWithEmailAndPassword(email: _email, password: _password);
    final User user = authResult.user;

    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => Home()),
    );
  } catch (e) {
    print(e.message);
  }}}}

또한 로그인 버튼을 누르면 항상이 메시지를받습니다.

I / flutter (3130) : Firebase 앱 '[DEFAULT]'가 생성되지 않았습니다. Firebase.initializeApp ()을 호출하세요.

아마도 이것이 그 이유일까요?

osaxma

FirebaseApp을 초기화해야합니다. 다음과 같이 주요 기능에서 수행 할 수 있습니다.

void main() async {
 
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
   
  runApp(MyApp());
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관