【发布时间】:2022-01-01 14:59:42
【问题描述】:
这是我的代码.. 这运行成功,没有错误,但是一旦我点击注册按钮,它就会抛出错误。
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MaterialApp(
home: Homepage(),
routes: {
'/home': (context) {
return Homepage();
},
'/first': (context) {
return First_Page();
},
},
));
}
class Homepage extends StatefulWidget {
const Homepage({Key? key}) : super(key: key);
@override
_HomepageState createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
final Future<FirebaseApp> _initialization = Firebase.initializeApp();
final _auth = FirebaseAuth.instance;
final _user = TextEditingController();
final _pass = TextEditingController();
String email = '';
String password = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text(
'Sign-Up',
),
centerTitle: true,
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsets.only(top: 250),
),
Container(
child: TextFormField(
controller: _user,
decoration: InputDecoration(
hintText: "Email-id",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
)),
),
),
SizedBox(
height: 10,
),
Container(
child: TextFormField(
controller: _pass,
decoration: InputDecoration(
hintText: "Password",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
)),
),
),
FlatButton(
color: Colors.blue,
child: Text('Sign-up'),
onPressed: () async {
await Firebase.initializeApp();
email = _user.toString();
password = _pass.toString();
final newuser = await _auth.createUserWithEmailAndPassword(
email: email.trim(),
password: password.trim(),
);
if (newuser != null) {
Navigator.pushNamed(context, '/First_Page');
} else
print('Error');
},
),
],
),
),
);
}
}
这些是我得到的所有错误
E/flutter (10268): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
[firebase_auth/invalid-email] The email address is badly formatted.
E/flutter (10268): #0 MethodChannelFirebaseAuth.createUserWithEmailAndPassword
(package:firebase_auth_platform_interface/src/method_channel
/method_channel_firebase_auth.dart:272:7)
E/flutter (10268): <asynchronous suspension>
E/flutter (10268): #1 FirebaseAuth.createUserWithEmailAndPassword
(package:firebase_auth/src/firebase_auth.dart:238:7)
E/flutter (10268): <asynchronous suspension>
E/flutter (10268): #2 _HomepageState.build.<anonymous closure>
(package:firebase/main.dart:79:31)
E/flutter (10268): <asynchronous suspension>
E/flutter (10268):
在 firebase 身份验证中,我已经启用了电子邮件登录方法,现在我没有得到我弄错的地方。 请告诉我。提前谢谢..
【问题讨论】:
-
我已经检查过了并应用了那里提到的所有方法,但仍然无法正常工作@FrankvanPuffelen
标签: firebase flutter authentication