1
0
mirror of https://github.com/nisrulz/flutter-examples.git synced 2026-08-25 01:05:36 +00:00
Files
flutter-examples/firebase_google_authentication/lib/Screens/SignUpPage.dart
Nishant Srivastava 5c53498119 refactor: standardize Dart and Android config across all 54 apps
- Bump all apps to sdk >=3.0.0 <4.0.0 and add flutter_lints + a shared
  analysis_options.yaml to every app (flutter analyze is now green repo-wide)
- Fix real compile errors in firebase_google_authentication and image_editor,
  plus deprecated APIs (Matrix4, SvgPicture.color, textScaleFactor),
  missing async 'mounted' guards, and misc lints via dart fix + manual fixes
- Align pubspec 'name' with each folder and Android namespace/applicationId
  with the documented github.nisrulz.* convention
- Convert bmi_calculator from a legacy Flutter module to a standard app
  with a proper android/ scaffold; fix missing android:exported in launcher
  manifests across 22 apps so all Android builds pass
- Untrack generated build files (GeneratedPluginRegistrant,
  .flutter-plugins-dependencies) and ignore them
2026-08-17 17:26:39 +02:00

284 lines
10 KiB
Dart

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_google_authentication/Services/google_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
class SignUpPage extends StatefulWidget {
final bool isLogin;
const SignUpPage(this.isLogin, {super.key});
@override
State<SignUpPage> createState() => _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage> {
late bool isLogin;
@override
void initState() {
super.initState();
isLogin = widget.isLogin;
}
bool loggingIn = false;
TextEditingController email = TextEditingController();
TextEditingController password = TextEditingController();
bool showPassword = false;
void showSnackBar() {
final snackBar = SnackBar(
content: Text('Invalid Credentials!'),
backgroundColor: Colors.red,
padding: EdgeInsets.symmetric(horizontal: 10),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
body: SingleChildScrollView(
child: SizedBox(
height: size.height,
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
(isLogin) ? 'Login' : 'SignUp',
style: GoogleFonts.alice(
fontWeight: FontWeight.bold,
fontSize: 29,
),
),
SizedBox(
height: 20,
),
SvgPicture.asset(
(isLogin) ? 'assets/signup.svg' : 'assets/signup.svg',
width: size.width * 0.5,
height: size.height * 0.3,
),
SizedBox(
height: 25,
),
Padding(
padding: const EdgeInsets.only(left: 30, right: 30),
child: TextField(
controller: email,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(29),
),
hintText: 'Your Email',
filled: true,
fillColor: Color(0xFFF1E6FF),
prefixIcon: Icon(
Icons.person,
color: Color(0xFF6F35A5),
),
),
),
),
SizedBox(
height: 15,
),
Padding(
padding: const EdgeInsets.only(left: 30, right: 30),
child: TextField(
controller: password,
obscureText: !showPassword,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(29),
),
hintText: 'Password',
filled: true,
fillColor: Color(0xFFF1E6FF),
prefixIcon: Icon(
Icons.lock,
color: Color(0xFF6F35A5),
),
suffixIcon: showPassword
? IconButton(
icon: Icon(
Icons.visibility_off,
color: Color(0xFF6F35A5),
),
onPressed: () {
setState(() {
showPassword = !showPassword;
});
},
)
: IconButton(
icon: Icon(
Icons.visibility,
color: Color(0xFF6F35A5),
),
onPressed: () {
setState(() {
showPassword = !showPassword;
});
},
)),
),
),
SizedBox(
height: 30,
),
SizedBox(
width: size.width * 0.8,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.symmetric(
vertical: 15, horizontal: 40),
backgroundColor: Color(0xFF6F35A5),
),
onPressed: () {
String emailText = email.text;
String passwordText = password.text;
!(isLogin)
? signUpClicked(emailText, passwordText, context)
: loginClicked(emailText, passwordText, context);
},
child: Text(
(isLogin) ? 'Login' : 'SignUp',
style: GoogleFonts.alata(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
),
),
),
SizedBox(
height: 18,
),
SizedBox(
width: size.width * 0.81,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: TextButton.icon(
style: TextButton.styleFrom(
padding: EdgeInsets.symmetric(
vertical: 15, horizontal: 40),
backgroundColor: Color(0xFF6F35A5),
),
onPressed: () {
final provider = Provider.of<GoogleSignInProvider>(
context,
listen: false);
provider.googleLogin().then((value) {
if (!context.mounted) return;
Navigator.popUntil(
context, (route) => route.isFirst);
}).catchError((onError) {
showSnackBar();
});
},
icon: FaIcon(
FontAwesomeIcons.google,
color: Colors.white,
),
label: Text(
(isLogin)
? 'Login with Google'
: 'SignUp with Google',
style: GoogleFonts.alata(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
),
),
),
SizedBox(
height: 20,
),
GestureDetector(
onTap: () {
setState(() {
isLogin = !isLogin;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
(isLogin)
? 'Don\'t have an account?'
: 'Already have an account?',
style: GoogleFonts.lato(
color: Color(0xFF6F35A5),
),
),
Text(
(isLogin) ? 'SignUp' : 'SignIn',
style: GoogleFonts.lato(
fontWeight: FontWeight.bold,
color: Color(0xFF6F35A5),
),
),
],
),
)
],
)
],
),
),
),
);
}
void signUpClicked(String email, String password, BuildContext context) {
FirebaseAuth.instance
.createUserWithEmailAndPassword(email: email, password: password)
.then((value) {
setState(() {
loggingIn = true;
});
Future.delayed(Duration(seconds: 1, milliseconds: 50), () {
if (!context.mounted) return;
Navigator.popUntil(context, (route) => route.isFirst);
});
}).catchError((e) {
showSnackBar();
});
}
bool loginClicked(String email, String password, BuildContext context) {
FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password)
.then((value) {
setState(() {
loggingIn = true;
});
Future.delayed(Duration(seconds: 1, milliseconds: 50), () {
if (!context.mounted) return;
Navigator.pop(context);
});
}).catchError((e) {
showSnackBar();
});
return loggingIn;
}
}