mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-08 12:39:17 +00:00
146 lines
4.3 KiB
Dart
146 lines
4.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
|
|
import 'package:github.nisrulz.todo_app/signIn.dart';
|
|
|
|
class Signup extends StatefulWidget {
|
|
const Signup({Key? key});
|
|
|
|
@override
|
|
State<Signup> createState() => _SignupState();
|
|
}
|
|
|
|
class _SignupState extends State<Signup> {
|
|
firebase_auth.FirebaseAuth firebaseauth = firebase_auth.FirebaseAuth.instance;
|
|
final TextEditingController _emailcontroller = TextEditingController();
|
|
final TextEditingController _passwordcontroller = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_emailcontroller.dispose();
|
|
_passwordcontroller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _signUp() async {
|
|
try {
|
|
final String email = _emailcontroller.text;
|
|
final String password = _passwordcontroller.text;
|
|
|
|
await firebaseauth.createUserWithEmailAndPassword(
|
|
email: email,
|
|
password: password,
|
|
);
|
|
|
|
Get.snackbar(
|
|
"Signed Up Success",
|
|
"You have successfully signed up.",
|
|
backgroundColor: Colors.green,
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
duration: Duration(seconds: 3),
|
|
);
|
|
|
|
Get.to(() => const Signin());
|
|
} catch (e) {
|
|
Get.snackbar(
|
|
"Sign Up Error",
|
|
e.toString(),
|
|
backgroundColor: Colors.red,
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
duration: Duration(seconds: 3),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: Container(
|
|
height: Get.size.height,
|
|
width: Get.size.width,
|
|
color: Colors.black,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Text(
|
|
"Sign Up",
|
|
style: TextStyle(
|
|
color: Colors.orange,
|
|
fontSize: 25,
|
|
fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 20),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
|
|
SizedBox(height: 20),
|
|
Container(
|
|
width: Get.size.width - 60,
|
|
height: 60,
|
|
child: Card(
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: Center(
|
|
child: TextField(
|
|
controller: _emailcontroller,
|
|
decoration: InputDecoration(
|
|
hintText: 'Email',
|
|
border: InputBorder.none,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 20),
|
|
Container(
|
|
width: Get.size.width - 60,
|
|
height: 60,
|
|
child: Card(
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: Center(
|
|
child: TextField(
|
|
controller: _passwordcontroller,
|
|
obscureText: true,
|
|
decoration: InputDecoration(
|
|
hintText: 'Password',
|
|
border: InputBorder.none,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: _signUp,
|
|
child: Text("Sign Up"),
|
|
),
|
|
SizedBox(height: 20),
|
|
GestureDetector(
|
|
onTap: () {
|
|
Get.to(() => Signin());
|
|
},
|
|
child: const Text(
|
|
"Already have an account? Login ",
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
decoration: TextDecoration.underline,
|
|
fontSize: 18),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|