Reputation: 3
I am new at flutter. I tried the tutorial of flutter using Android studio and got this error.
[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(ERROR_INVALID_EMAIL, The email address is badly formatted., null)
The email address I input was true. like, [email protected]
Why this error occurred and how can i fix it?
I did reverse some packages before one, perhaps is it the reason?
This is my registrationpage.dart
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:true_rider/brand_colors.dart';
import 'package:true_rider/screens/loginpage.dart';
import 'package:true_rider/widgets/TaxiButton.dart';
class RegistrationPage extends StatelessWidget {
static const String id = 'register';
final FirebaseAuth _auth = FirebaseAuth.instance;
var fullNameController = TextEditingController();
var phoneController = TextEditingController();
var emailController = TextEditingController();
var passwordController = TextEditingController();
void registerUser() async {
final FirebaseUser user = (await _auth.createUserWithEmailAndPassword(
email: 'emailController.text',
password: 'passwordController.text',
)).user;
if (user != null) {
print('registration successful');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
SizedBox(height: 70,),
Image(
alignment: Alignment.center,
height: 100.0,
width: 100.0,
image: AssetImage('images'
'/logo.png'),
),
SizedBox(height: 40,),
Text('Create a Rider\'s Account',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 25, fontFamily: 'Brand-Bold'),
),
Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
TextField(
controller: fullNameController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: 'Full name',
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
style: TextStyle(fontSize: 14),
),
SizedBox(height: 10,),
TextField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email address',
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
style: TextStyle(fontSize: 14),
),
SizedBox(height: 10,),
TextField(
controller: phoneController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: 'Phone number',
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
style: TextStyle(fontSize: 14),
),
SizedBox(height: 10,),
TextField(
controller: passwordController,
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
style: TextStyle(fontSize: 14),
),
SizedBox(height: 40,),
TaxiButton(
title: 'REGISTER',
color: BrandColors.colorGreen,
onPressed: () {
registerUser();
},
),
],
),
),
FlatButton(
onPressed: (){
Navigator.pushNamedAndRemoveUntil(context, LoginPage.id, (route) => false);
},
child: Text ('Already have a RIDER account? Log in')
),
],
),
),
),
),
);
}
}
And this is my longinpage.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:true_rider/brand_colors.dart';
import 'package:true_rider/screens/registrationpage.dart';
import 'package:true_rider/widgets/TaxiButton.dart';
class LoginPage extends StatelessWidget {
static const String id = 'login';
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
SizedBox(height: 70,),
Image(
alignment: Alignment.center,
height: 100.0,
width: 100.0,
image: AssetImage('images'
'/logo.png'),
),
SizedBox(height: 40,),
Text('Sign In as a Rider',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 25, fontFamily: 'Brand-Bold'),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
TextField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email address',
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
style: TextStyle(fontSize: 14),
),
SizedBox(height: 10,),
TextField(
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
style: TextStyle(fontSize: 14),
),
SizedBox(height: 40,),
TaxiButton(
title: 'LOGIN',
color: BrandColors.colorGreen,
onPressed: () {
},
),
],
),
),
FlatButton(
onPressed: (){
Navigator.pushNamedAndRemoveUntil(context, RegistrationPage.id, (route) => false);
},
child: Text ('Don\'t have an account, sign up here')
),
],
),
),
),
),
);
}
}
and this is my main.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:true_rider/screens/loginpage.dart';
import 'package:true_rider/screens/mainpage.dart';
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:true_rider/screens/registrationpage.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final FirebaseApp app = await FirebaseApp.configure(
name: 'db2',
options: Platform.isIOS || Platform.isMacOS
? const FirebaseOptions(
googleAppID: '1:297855924061:ios:c6de2b69b03a5be8',
gcmSenderID: '297855924061',
databaseURL: 'https://flutterfire-cd2f7.firebaseio.com',
)
: const FirebaseOptions(
googleAppID: '1:17165000282:android:c47ee5756c37488cda4263',
apiKey: 'AIzaSyCTaNcAqsUkUBaqSCAqEMDH4ddweQxwHbc',
databaseURL: 'https://noob-48298.firebaseio.com',
),
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
fontFamily: 'Brand-Regular',
primarySwatch: Colors.blue,
),
initialRoute: RegistrationPage.id,
routes: {
RegistrationPage.id: (context) => RegistrationPage(),
LoginPage.id: (context) => LoginPage(),
MainPage.id: (context) => MainPage(),
},);
}
}
This is my mainpage.dart
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
class MainPage extends StatefulWidget {
static const String id = 'mainpage';
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('MainPage'),
),
body: Center(
child: MaterialButton(
onPressed: (){
DatabaseReference dbref = FirebaseDatabase.instance.reference().child('Test');
dbref.set('IsConnected');
},
height: 50,
minWidth: 300,
color: Colors.green,
child: Text('Test Connection'),
),
),
);
}
}
This is my TaxiButton.dart
import 'package:flutter/material.dart';
class TaxiButton extends StatelessWidget {
final String title;
final Color color;
final Function onPressed;
TaxiButton({this.title, this.onPressed, this.color});
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: onPressed,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(25)
),
color: color,
textColor: Colors.white,
child: Container(
height: 50,
child: Center(
child: Text(
title,
style: TextStyle(fontSize: 18, fontFamily: 'Brand-Bold'),
),
),
),
);
}
}
And this is my pubspec.yaml.
name: true_rider
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
firebase_core: ^0.4.4
firebase_auth: 0.16.1
firebase_database: ^3.1.5
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- images/
fonts:
- family: Brand-Bold
fonts:
- asset: fonts/bolt-semibold.ttf
- family: Brand-Regular
fonts:
- asset: fonts/bolt-regular.ttf
Upvotes: 0
Views: 740
Reputation: 598951
You're trying to create the user with:
_auth.createUserWithEmailAndPassword(
email: 'emailController.text',
password: 'passwordController.text',
)
Since the 'emailController.text'
and 'passwordController.text'
have quotes around them, they are literal strings. So those literal strings are passed to Firebase Authentication, and that first one is not a valid email address.
You probable want the value that the user typed in those control to be used, in which case you should remove the quotes:
_auth.createUserWithEmailAndPassword(
email: emailController.text,
password: passwordController.text,
)
Upvotes: 1