mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-08 12:39:17 +00:00
148 lines
4.3 KiB
Dart
148 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/Home.dart';
|
|
import 'package:github.nisrulz.todo_app/signUp.dart';
|
|
|
|
class Signin extends StatefulWidget {
|
|
const Signin({Key? key});
|
|
|
|
@override
|
|
State<Signin> createState() => _SigninState();
|
|
}
|
|
|
|
class _SigninState extends State<Signin> {
|
|
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> _Signin() async {
|
|
try {
|
|
final String email = _emailcontroller.text;
|
|
final String password = _passwordcontroller.text;
|
|
|
|
await firebaseauth.signInWithEmailAndPassword(
|
|
email: email,
|
|
password: password,
|
|
);
|
|
|
|
Get.snackbar(
|
|
"Sign In Success",
|
|
"You have successfully signed in.",
|
|
backgroundColor: Colors.green,
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
duration: Duration(seconds: 3),
|
|
);
|
|
|
|
|
|
Get.to(() => HomePage());
|
|
} catch (e) {
|
|
Get.snackbar(
|
|
"Sign In 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(
|
|
"Login ",
|
|
style: TextStyle(
|
|
color: Colors.green,
|
|
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: _Signin,
|
|
child: Text("Sign In"),
|
|
),
|
|
SizedBox(height: 20),
|
|
GestureDetector(
|
|
onTap: () {
|
|
Get.to(() => Signup());
|
|
},
|
|
child: const Text(
|
|
"Don't have an account? Sign Up",
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
decoration: TextDecoration.underline,
|
|
fontSize: 18),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|