Initial commit of Flutter project
This commit is contained in:
@@ -1,60 +1,97 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:glowwheels/provider/shop_provider.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../screens/main_screen.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
final TextEditingController _emailController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
bool _obscurePassword = true;
|
||||
|
||||
void _handleLogin(BuildContext context) async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
final shopProvider = Provider.of<ShopProvider>(context, listen: false);
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
final success = await shopProvider.login(
|
||||
_emailController.text.trim(),
|
||||
_passwordController.text.trim(),
|
||||
);
|
||||
|
||||
setState(() => _isLoading = false);
|
||||
|
||||
if (success) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => MainScreen()),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Login failed. Check credentials.')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
import 'main_screen.dart';
|
||||
class LoginScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: SingleChildScrollView(
|
||||
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
// Top Banner
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color.fromRGBO(80, 166, 242, 0.66),
|
||||
Color.fromRGBO(168, 134, 255, 0.66),
|
||||
Color.fromRGBO(86, 88, 255, 0.3828),
|
||||
Color.fromRGBO(214, 246, 255, 0.66),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.only(bottomRight: Radius.elliptical(300, 110), )
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color.fromRGBO(80, 166, 242, 0.66),
|
||||
Color.fromRGBO(168, 134, 255, 0.66),
|
||||
Color.fromRGBO(86, 88, 255, 0.38),
|
||||
Color.fromRGBO(214, 246, 255, 0.66),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomRight: Radius.elliptical(300, 110),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 30),
|
||||
SizedBox(height: 30),
|
||||
Image.asset('assets/images/signinlogo.png', height: 250),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
const SizedBox(height: 30),
|
||||
SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Welcome back!", style:
|
||||
GoogleFonts.istokWeb(
|
||||
fontSize: 18,color: Color.fromRGBO(25, 25, 112, 0.87)
|
||||
,fontWeight: FontWeight.w700
|
||||
)),
|
||||
|
||||
Text("Welcome back!",
|
||||
style: GoogleFonts.istokWeb(
|
||||
fontSize: 18,
|
||||
color: Color.fromRGBO(25, 25, 112, 0.87),
|
||||
fontWeight: FontWeight.w700,
|
||||
)),
|
||||
Container(
|
||||
width: 200,
|
||||
child: Text("Please sign in to continue",
|
||||
style:GoogleFonts.radioCanada(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
height: 0.9,
|
||||
color: Color.fromRGBO(25, 25, 112, 0.87)
|
||||
style: GoogleFonts.radioCanada(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
height: 0.9,
|
||||
color: Color.fromRGBO(25, 25, 112, 0.87),
|
||||
)),
|
||||
),
|
||||
],
|
||||
@@ -64,48 +101,68 @@ class LoginScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Login Form
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: Form(
|
||||
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
||||
const SizedBox(height: 20),
|
||||
Text('Enter Email Id',style:GoogleFonts.radioCanada(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
//color: Color.fromRGBO(25, 25, 112, 0.87)
|
||||
)),
|
||||
const SizedBox(height: 5),
|
||||
TextField(
|
||||
SizedBox(height: 20),
|
||||
Text('Enter Email Id', style: GoogleFonts.radioCanada(fontSize: 16)),
|
||||
SizedBox(height: 5),
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your email';
|
||||
}
|
||||
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value)) {
|
||||
return 'Enter a valid email';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
|
||||
hintText: 'abcd@gmail.com',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(15.0)
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text('Enter Password',style:GoogleFonts.radioCanada(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
//color: Color.fromRGBO(25, 25, 112, 0.87)
|
||||
)),
|
||||
const SizedBox(height: 5),
|
||||
TextField(
|
||||
obscureText: true,
|
||||
SizedBox(height: 20),
|
||||
Text('Enter Password', style: GoogleFonts.radioCanada(fontSize: 16)),
|
||||
SizedBox(height: 5),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: _obscurePassword,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
|
||||
hintText: 'Enter your password',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(15.0)
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscurePassword ? Icons.visibility_off : Icons.visibility,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscurePassword = !_obscurePassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
suffixIcon: Icon(Icons.remove_red_eye_outlined),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
SizedBox(height: 30),
|
||||
|
||||
// Login Button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
@@ -116,16 +173,16 @@ class LoginScreen extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context)=>MainScreen()));
|
||||
},
|
||||
child: Text('Login', style:
|
||||
|
||||
GoogleFonts.inter(
|
||||
fontSize: 18,color: Colors.white
|
||||
,fontWeight: FontWeight.w600
|
||||
)
|
||||
|
||||
onPressed: _isLoading ? null : () => _handleLogin(context),
|
||||
child: _isLoading
|
||||
? CircularProgressIndicator(color: Colors.white)
|
||||
: Text(
|
||||
'Login',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -138,4 +195,4 @@ class LoginScreen extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user