Initial Flutter project added

This commit is contained in:
Abhishek Mali
2025-11-28 10:14:30 +05:30
commit 1df218c097
141 changed files with 5679 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import 'welcome_screen.dart';
class DashboardScreen extends StatelessWidget {
const DashboardScreen({super.key});
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthProvider>(context);
final name = auth.user?['customer_name'] ?? 'User';
return Scaffold(
appBar: AppBar(
title: const Text("Dashboard"),
actions: [
IconButton(
icon: const Icon(Icons.logout),
onPressed: () async {
await auth.logout();
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (_) => const WelcomeScreen()), (r) => false);
},
)
],
),
body: Padding(
padding: const EdgeInsets.all(18),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text("Welcome, ${name}", style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
const SizedBox(height: 12),
const Text("Your dashboard will appear here. Build shipment list, tracking, create shipment screens next."),
]),
),
);
}
}

View File

@@ -0,0 +1,70 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import '../widgets/rounded_input.dart';
import '../widgets/primary_button.dart';
import 'dashboard_screen.dart';
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);
// Basic validation
final loginId = cLoginId.text.trim();
final password = cPassword.text.trim();
if (loginId.isEmpty || password.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Please enter login id and password')));
return;
}
final res = await auth.login(loginId, password);
// Your controller returns { success: true/false, message, token, user }
if (res['success'] == true) {
// Navigate to dashboard
if (!mounted) return;
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const DashboardScreen()));
} 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;
return Scaffold(
appBar: AppBar(title: const Text('Login')),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: width * 0.06, vertical: 20),
child: Column(
children: [
RoundedInput(controller: cLoginId, hint: 'Email / Mobile / Customer ID', keyboardType: TextInputType.text),
const SizedBox(height: 12),
RoundedInput(controller: cPassword, hint: 'Password', obscure: true),
const SizedBox(height: 18),
PrimaryButton(label: 'Login', onTap: _login, busy: auth.loading),
],
),
),
);
}
}

View File

@@ -0,0 +1,67 @@
import 'package:flutter/material.dart';
import '../widgets/rounded_input.dart';
import '../widgets/primary_button.dart';
import '../services/request_service.dart';
import 'waiting_screen.dart';
class OtpScreen extends StatefulWidget {
final Map<String, dynamic> signupPayload;
const OtpScreen({super.key, required this.signupPayload});
@override
State<OtpScreen> createState() => _OtpScreenState();
}
class _OtpScreenState extends State<OtpScreen> {
final otpController = TextEditingController();
bool verifying = false;
static const String defaultOtp = '123456'; // default OTP as you said
void _verifyAndSubmit() async {
final entered = otpController.text.trim();
if (entered.length != 6) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter 6 digit OTP')));
return;
}
if (entered != defaultOtp) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Invalid OTP')));
return;
}
setState(() => verifying = true);
// send signup payload to backend
final res = await RequestService().sendSignup(widget.signupPayload);
setState(() => verifying = false);
if (res['status'] == true || res['status'] == 'success') {
// navigate to waiting screen
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const WaitingScreen()));
} else {
final message = res['message']?.toString() ?? 'Failed';
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
}
}
@override
Widget build(BuildContext context) {
final pad = MediaQuery.of(context).size.width * 0.06;
return Scaffold(
appBar: AppBar(title: const Text("OTP Verification")),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: pad, vertical: 20),
child: Column(children: [
const Text("Enter the 6-digit OTP sent to your mobile/email. (Default OTP: 123456)"),
const SizedBox(height: 20),
RoundedInput(controller: otpController, hint: "Enter OTP", keyboardType: TextInputType.number),
const SizedBox(height: 14),
PrimaryButton(label: "Verify & Submit", onTap: _verifyAndSubmit, busy: verifying),
]),
),
);
}
}

View File

@@ -0,0 +1,79 @@
import 'package:flutter/material.dart';
import '../widgets/rounded_input.dart';
import '../widgets/primary_button.dart';
import 'otp_screen.dart';
class SignupScreen extends StatefulWidget {
const SignupScreen({super.key});
@override
State<SignupScreen> createState() => _SignupScreenState();
}
class _SignupScreenState extends State<SignupScreen> {
final cName = TextEditingController();
final cCompany = TextEditingController();
final cDesignation = TextEditingController();
final cEmail = TextEditingController();
final cMobile = TextEditingController();
final cAddress = TextEditingController();
final cPincode = TextEditingController();
bool sending = false;
void _sendOtp() async {
// We don't call backend for OTP here per your flow - OTP is default 123456.
// Validate minimal
if (cName.text.trim().isEmpty || cCompany.text.trim().isEmpty || cEmail.text.trim().isEmpty || cMobile.text.trim().isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Please fill the required fields')));
return;
}
setState(() => sending = true);
await Future.delayed(const Duration(milliseconds: 600)); // UI feel
setState(() => sending = false);
// Navigate to OTP screen with collected data
final data = {
'customer_name': cName.text.trim(),
'company_name': cCompany.text.trim(),
'designation': cDesignation.text.trim(),
'email': cEmail.text.trim(),
'mobile_no': cMobile.text.trim(),
'address': cAddress.text.trim(),
'pincode': cPincode.text.trim(),
};
Navigator.of(context).push(MaterialPageRoute(builder: (_) => OtpScreen(signupPayload: data)));
}
@override
Widget build(BuildContext context) {
final pad = MediaQuery.of(context).size.width * 0.06;
return Scaffold(
appBar: AppBar(title: const Text("Create Account")),
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: pad),
child: SingleChildScrollView(
child: Column(children: [
const SizedBox(height: 16),
RoundedInput(controller: cName, hint: "Customer name"),
const SizedBox(height: 12),
RoundedInput(controller: cCompany, hint: "Company name"),
const SizedBox(height: 12),
RoundedInput(controller: cDesignation, hint: "Designation (optional)"),
const SizedBox(height: 12),
RoundedInput(controller: cEmail, hint: "Email", keyboardType: TextInputType.emailAddress),
const SizedBox(height: 12),
RoundedInput(controller: cMobile, hint: "Mobile", keyboardType: TextInputType.phone),
const SizedBox(height: 12),
RoundedInput(controller: cAddress, hint: "Address", maxLines: 3),
const SizedBox(height: 12),
RoundedInput(controller: cPincode, hint: "Pincode", keyboardType: TextInputType.number),
const SizedBox(height: 20),
PrimaryButton(label: "Send OTP", onTap: _sendOtp, busy: sending),
const SizedBox(height: 14),
]),
),
),
),
);
}
}

View File

@@ -0,0 +1,52 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import 'dashboard_screen.dart';
import 'welcome_screen.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
_init();
}
void _init() async {
// small delay to show logo
await Future.delayed(const Duration(milliseconds: 900));
final auth = Provider.of<AuthProvider>(context, listen: false);
// ensure provider has loaded prefs
await Future.delayed(const Duration(milliseconds: 300));
if (auth.isLoggedIn) {
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const DashboardScreen()));
} else {
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const WelcomeScreen()));
}
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Container(
width: size.width * 0.34,
height: size.width * 0.34,
decoration: BoxDecoration(shape: BoxShape.circle, color: Theme.of(context).primaryColor.withOpacity(0.14)),
child: Center(child: Text("K", style: TextStyle(fontSize: 48, fontWeight: FontWeight.bold, color: Theme.of(context).primaryColor))),
),
const SizedBox(height: 18),
const Text("Kent Logistics", style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600)),
]),
),
);
}
}

View File

@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
class WaitingScreen extends StatelessWidget {
const WaitingScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Request Submitted")),
body: Padding(
padding: const EdgeInsets.all(18.0),
child: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Icon(Icons.hourglass_top, size: 72, color: Theme.of(context).primaryColor),
const SizedBox(height: 16),
const Text(
"Signup request submitted successfully.",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
const Text(
"Please wait up to 24 hours for admin approval. You will receive an email once approved.",
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () {
Navigator.of(context).popUntil((route) => route.isFirst);
},
child: const Padding(padding: EdgeInsets.symmetric(horizontal: 14, vertical: 12), child: Text("Back to Home")),
style: ElevatedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))),
),
]),
),
),
);
}
}

View File

@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'signup_screen.dart';
import 'login_screen.dart';
class WelcomeScreen extends StatelessWidget {
const WelcomeScreen({super.key});
@override
Widget build(BuildContext context) {
final w = MediaQuery.of(context).size.width;
return Scaffold(
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: w * 0.06),
child: Column(
children: [
const SizedBox(height: 28),
Align(alignment: Alignment.centerLeft, child: Text("Welcome", style: Theme.of(context).textTheme.headlineSmall)),
const SizedBox(height: 12),
const Text(
"Register to access Kent Logistics services. After signup admin will review and approve your request. Approval may take up to 24 hours.",
style: TextStyle(fontSize: 15),
),
const Spacer(),
ElevatedButton(
onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const SignupScreen())),
child: const SizedBox(width: double.infinity, child: Center(child: Padding(padding: EdgeInsets.all(14.0), child: Text("Create Account")))),
style: ElevatedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))),
),
const SizedBox(height: 12),
OutlinedButton(
onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const LoginScreen())),
child: const SizedBox(width: double.infinity, child: Center(child: Padding(padding: EdgeInsets.all(14.0), child: Text("Login")))),
style: OutlinedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))),
),
const SizedBox(height: 24),
],
),
),
),
);
}
}