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);
|
|
|
|
|
|
|
|
|
|
final loginId = cLoginId.text.trim();
|
|
|
|
|
final password = cPassword.text.trim();
|
2025-12-03 11:57:05 +05:30
|
|
|
|
2025-11-28 10:14:30 +05:30
|
|
|
if (loginId.isEmpty || password.isEmpty) {
|
2025-12-03 11:57:05 +05:30
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
const SnackBar(content: Text('Please enter login id and password')),
|
|
|
|
|
);
|
2025-11-28 10:14:30 +05:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 11:57:05 +05:30
|
|
|
final res = await auth.login(context, loginId, password);
|
2025-11-28 10:14:30 +05:30
|
|
|
|
|
|
|
|
if (res['success'] == true) {
|
|
|
|
|
if (!mounted) return;
|
2025-12-03 11:57:05 +05:30
|
|
|
Navigator.of(context).pushReplacement(
|
|
|
|
|
MaterialPageRoute(builder: (_) => const MainBottomNav()),
|
|
|
|
|
);
|
2025-11-28 10:14:30 +05:30
|
|
|
} else {
|
|
|
|
|
final msg = res['message']?.toString() ?? 'Login failed';
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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-11-28 10:14:30 +05:30
|
|
|
return Scaffold(
|
2025-12-03 11:57:05 +05:30
|
|
|
appBar: AppBar(
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pushReplacement(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (_) => const WelcomeScreen()),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
title: const Text('Login'),
|
|
|
|
|
),
|
|
|
|
|
|
2025-11-28 10:14:30 +05:30
|
|
|
body: Padding(
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: width * 0.06, vertical: 20),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
2025-12-03 11:57:05 +05:30
|
|
|
RoundedInput(
|
|
|
|
|
controller: cLoginId,
|
|
|
|
|
hint: 'Email / Mobile / Customer ID',
|
|
|
|
|
),
|
2025-11-28 10:14:30 +05:30
|
|
|
const SizedBox(height: 12),
|
2025-12-03 11:57:05 +05:30
|
|
|
RoundedInput(
|
|
|
|
|
controller: cPassword,
|
|
|
|
|
hint: 'Password',
|
|
|
|
|
obscure: true,
|
|
|
|
|
),
|
2025-11-28 10:14:30 +05:30
|
|
|
const SizedBox(height: 18),
|
|
|
|
|
PrimaryButton(label: 'Login', onTap: _login, busy: auth.loading),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|