Skip to content

Instantly share code, notes, and snippets.

@cankush625
Created October 28, 2020 19:45
Show Gist options
  • Save cankush625/b87dfdaec1d8ed264e44c8c20596f83f to your computer and use it in GitHub Desktop.
Save cankush625/b87dfdaec1d8ed264e44c8c20596f83f to your computer and use it in GitHub Desktop.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
class AccountRegistration extends StatefulWidget {
@override
_AccountRegistrationState createState() => _AccountRegistrationState();
}
class _AccountRegistrationState extends State<AccountRegistration> {
var fs = FirebaseFirestore.instance;
var authc = FirebaseAuth.instance;
String name;
String email;
String password;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Registration'),
),
body: Center(
child: Container(
width: 300,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
keyboardType: TextInputType.text,
onChanged: (value) {
name = value;
},
decoration: InputDecoration(
hintText: "Enter Name",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
SizedBox(
height: 10,
),
TextField(
keyboardType: TextInputType.emailAddress,
onChanged: (value) {
email = value;
},
decoration: InputDecoration(
hintText: "Enter Email",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
SizedBox(
height: 10,
),
TextField(
obscureText: true,
onChanged: (value) {
password = value;
},
decoration: InputDecoration(
hintText: "Enter Password",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
SizedBox(
height: 10,
),
Material(
color: Colors.lightBlueAccent,
borderRadius: BorderRadius.circular(10),
elevation: 10,
child: MaterialButton(
minWidth: 200,
height: 40,
child: Text('Submit'),
onPressed: () async {
try {
var user = await authc.createUserWithEmailAndPassword(
email: email,
password: password,
);
await fs.collection("user").doc(email).set({
"name": name,
"email": email,
});
print(email);
print(password);
print(user);
if (user.additionalUserInfo.isNewUser == true) {
Navigator.pushNamed(context, "chat");
}
} catch (e) {
print(e);
}
},
),
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment