You are on page 1of 5

UOL

CHENAB CAMPUS

DEPARTMENT OF COMPUTER SCIENCE & IT

NAME: ASAD AMJAD

CLASS: BSCS-7

SAP: 70059627

SUBMITTED TO: MR. QAMMAR UD DIN

DATE: 21-12-2021
SIGN-UP PAGE
Create_user.dart:

import 'package:firebase_auth/firebase_auth.dart';

class CreateUser {
user(String email, String password) async {
try {
UserCredential userCredential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(email: email, password: password);
return User;
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
print('The password provided is too weak.');
} else if (e.code == 'email-already-in-use') {
print('The account already exists for that email.');
}
} catch (e) {
print(e);
}
}
}

Sing_up_page.dart

import 'package:flutter/material.dart';
import 'package:mobile_app_dev_proj/create_user.dart';

class LoginPage extends StatefulWidget {


const LoginPage({Key? key}) : super(key: key);

@override
_LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {


@override
Widget build(BuildContext context) {
//textfield controllers.
final controllerUserName = TextEditingController();
final controllerPassword = TextEditingController();

return Column(
children: [
//User name Field
TextField(
controller: controllerUserName,
decoration: const InputDecoration(
labelText: 'User Name', prefixIcon: Icon(Icons.text_fields)),
),
//Password Field
TextField(
controller: controllerPassword,
decoration: const InputDecoration(
labelText: 'Password', prefixIcon: Icon(Icons.text_fields)),
),
//Create Account Button
Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
child: const Text(
"Create Account",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
onTap: () {
CreateUser _user = CreateUser();
_user.user(controllerUserName.text, controllerPassword.text);
},
),
),
],
);
}
}

Main.dart:

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:mobile_app_dev_proj/sing_up_page.dart';

Future main() async {


WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}

class MyApp extends StatelessWidget {


const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text("home"),
),
body: const LoginPage()),
);
}
}

You might also like