2025-11-28 10:14:30 +05:30
|
|
|
import 'package:flutter/material.dart';
|
2025-12-03 11:57:05 +05:30
|
|
|
import 'package:kent_logistics_app/screens/welcome_screen.dart';
|
2025-11-28 10:14:30 +05:30
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import '../providers/auth_provider.dart';
|
|
|
|
|
import '../widgets/rounded_input.dart';
|
|
|
|
|
import '../widgets/primary_button.dart';
|
2025-12-03 11:57:05 +05:30
|
|
|
import 'main_bottom_nav.dart';
|
2025-11-28 10:14:30 +05:30
|
|
|
|
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
|
|
|
const LoginScreen({super.key});
|
|
|
|
|
@override
|
|
|
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
|
|
|
final cLoginId = TextEditingController();
|
|
|
|
|
final cPassword = TextEditingController();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
cLoginId.dispose();
|
|
|
|
|
cPassword.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _login() async {
|
|
|
|
|
final auth = Provider.of<AuthProvider>(context, listen: false);
|
|
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
final id = cLoginId.text.trim();
|
|
|
|
|
final pass = cPassword.text.trim();
|
2025-12-03 11:57:05 +05:30
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
if (id.isEmpty || pass.isEmpty) {
|
|
|
|
|
ScaffoldMessenger.of(context)
|
|
|
|
|
.showSnackBar(const SnackBar(content: Text("Please fill all fields")));
|
2025-11-28 10:14:30 +05:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
final res = await auth.login(context, id, pass);
|
2025-11-28 10:14:30 +05:30
|
|
|
|
|
|
|
|
if (res['success'] == true) {
|
|
|
|
|
if (!mounted) return;
|
2025-12-11 18:36:11 +05:30
|
|
|
Navigator.pushReplacement(
|
|
|
|
|
context,
|
2025-12-03 11:57:05 +05:30
|
|
|
MaterialPageRoute(builder: (_) => const MainBottomNav()),
|
|
|
|
|
);
|
2025-11-28 10:14:30 +05:30
|
|
|
} else {
|
2025-12-11 18:36:11 +05:30
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(content: Text(res['message'] ?? "Login failed")),
|
|
|
|
|
);
|
2025-11-28 10:14:30 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final auth = Provider.of<AuthProvider>(context);
|
|
|
|
|
final width = MediaQuery.of(context).size.width;
|
2025-12-03 11:57:05 +05:30
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
/// ⭐ RESPONSIVE SCALE
|
|
|
|
|
final scale = (width / 390).clamp(0.85, 1.25);
|
|
|
|
|
|
2025-11-28 10:14:30 +05:30
|
|
|
return Scaffold(
|
2025-12-11 18:36:11 +05:30
|
|
|
backgroundColor: const Color(0xFFE8F0FF),
|
2025-12-03 11:57:05 +05:30
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
body: Stack(
|
|
|
|
|
children: [
|
|
|
|
|
/// 🔵 Floating Back Button (Responsive Position + Size)
|
|
|
|
|
Positioned(
|
|
|
|
|
top: 40 * scale,
|
|
|
|
|
left: 12 * scale,
|
|
|
|
|
child: Material(
|
|
|
|
|
elevation: 6 * scale,
|
|
|
|
|
color: Colors.indigo.shade700,
|
|
|
|
|
shape: const CircleBorder(),
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.pushReplacement(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (_) => const WelcomeScreen()),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.all(10 * scale),
|
|
|
|
|
child: Icon(Icons.arrow_back,
|
|
|
|
|
color: Colors.white, size: 20 * scale),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
),
|
2025-12-11 18:36:11 +05:30
|
|
|
),
|
|
|
|
|
|
|
|
|
|
/// 📦 Center White Card (Responsive)
|
|
|
|
|
Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: width * 0.87,
|
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
|
vertical: 28 * scale,
|
|
|
|
|
horizontal: 20 * scale,
|
|
|
|
|
),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(22 * scale),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.black12,
|
|
|
|
|
blurRadius: 18 * scale,
|
|
|
|
|
spreadRadius: 1,
|
|
|
|
|
offset: Offset(0, 6 * scale),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"Login",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 26 * scale,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.indigo.shade700,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 25 * scale),
|
|
|
|
|
|
|
|
|
|
/// Login ID Input
|
|
|
|
|
Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFFD8E7FF),
|
|
|
|
|
borderRadius: BorderRadius.circular(14 * scale),
|
|
|
|
|
),
|
|
|
|
|
child: RoundedInput(
|
|
|
|
|
controller: cLoginId,
|
|
|
|
|
hint: "Email / Mobile / Customer ID",
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 16 * scale),
|
|
|
|
|
|
|
|
|
|
/// Password Input
|
|
|
|
|
Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFFD8E7FF),
|
|
|
|
|
borderRadius: BorderRadius.circular(14 * scale),
|
|
|
|
|
),
|
|
|
|
|
child: RoundedInput(
|
|
|
|
|
controller: cPassword,
|
|
|
|
|
hint: "Password",
|
|
|
|
|
obscure: true,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 25 * scale),
|
|
|
|
|
|
|
|
|
|
/// Login Button
|
|
|
|
|
PrimaryButton(
|
|
|
|
|
label: "Login",
|
|
|
|
|
onTap: _login,
|
|
|
|
|
busy: auth.loading,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
),
|
2025-12-11 18:36:11 +05:30
|
|
|
),
|
|
|
|
|
],
|
2025-11-28 10:14:30 +05:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|