edit profile changes

master
gitadmin 1 month ago
parent 249ff4206c
commit 00f3473d02

@ -9,8 +9,10 @@ void main() => runApp(const MaterialApp(home: AvailabilityScreen()));
class AvailabilityScreen extends StatefulWidget { class AvailabilityScreen extends StatefulWidget {
const AvailabilityScreen({super.key}); const AvailabilityScreen({super.key});
@override @override
_AvailabilityScreenState createState() => _AvailabilityScreenState(); _AvailabilityScreenState createState() => _AvailabilityScreenState();
} }
class _AvailabilityScreenState extends State<AvailabilityScreen> { class _AvailabilityScreenState extends State<AvailabilityScreen> {
@ -23,6 +25,7 @@ class _AvailabilityScreenState extends State<AvailabilityScreen> {
TimeOfDay? _weekdayEndTime; TimeOfDay? _weekdayEndTime;
TimeOfDay? _weekendStartTime; TimeOfDay? _weekendStartTime;
TimeOfDay? _weekendEndTime; TimeOfDay? _weekendEndTime;
int currentStep = 3;
final List<String> _days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; final List<String> _days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
@ -93,17 +96,17 @@ class _AvailabilityScreenState extends State<AvailabilityScreen> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Step indicator // Step indicator
Text('Step 5/5', Text("Step $currentStep/5",),
style: fontTextStyle(14, Colors.grey, FontWeight.normal)),
const SizedBox(height: 4),
Row( Row(
children: List.generate(4, (index) { children: List.generate(5, (index) {
final isFilled = index < currentStep;
return Expanded( return Expanded(
child: Container( child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2), margin: const EdgeInsets.symmetric(horizontal: 2),
height: 5, height: 5,
decoration: BoxDecoration( decoration: BoxDecoration(
color: index < 4 ? const Color(0xFFC3C4C4) : Colors.grey, color: isFilled ? const Color(0xFF0D3771) : const Color(0xFFE6E6E6),
borderRadius: BorderRadius.circular(2), borderRadius: BorderRadius.circular(2),
), ),
), ),

@ -1,7 +1,12 @@
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:supplier_new/common/settings.dart'; import 'package:supplier_new/common/settings.dart';
import 'package:supplier_new/profile/source_location.dart';
import '../resources/driver_details.dart';
import '../resources/drivers_model.dart';
import '../resources/resources_drivers.dart';
import 'availability.dart';
class FleetEmployees extends StatefulWidget { class FleetEmployees extends StatefulWidget {
const FleetEmployees({super.key}); const FleetEmployees({super.key});
@ -11,14 +16,16 @@ class FleetEmployees extends StatefulWidget {
} }
class _FleetEmployeesState extends State<FleetEmployees> { class _FleetEmployeesState extends State<FleetEmployees> {
final _formKey = GlobalKey<FormState>(); bool isLoading = false;
int currentStep = 1;
List<DriversModel> driversList = [];
// Controllers // Controllers for adding new driver
final _formKey = GlobalKey<FormState>();
final _nameCtrl = TextEditingController(); final _nameCtrl = TextEditingController();
final _mobileCtrl = TextEditingController(); final _mobileCtrl = TextEditingController();
final _altMobileCtrl = TextEditingController(); final _altMobileCtrl = TextEditingController();
// Dropdowns
final List<String> licenseNumbers = [ final List<String> licenseNumbers = [
"UP3220050012345", "UP3220050012345",
"UP3220050012355", "UP3220050012355",
@ -30,10 +37,30 @@ class _FleetEmployeesState extends State<FleetEmployees> {
final List<String> yearOptions = ["1", "2", "3", "4", "5"]; final List<String> yearOptions = ["1", "2", "3", "4", "5"];
String? selectedExperience; String? selectedExperience;
// Data bucket @override
final List<Map<String, dynamic>> _drivers = []; void initState() {
super.initState();
_fetchDrivers();
}
Future<void> _fetchDrivers() async {
setState(() => isLoading = true);
try {
final response = await AppSettings.getDrivers();
final data = (jsonDecode(response)['data'] as List)
.map((e) => DriversModel.fromJson(e))
.toList();
if (!mounted) return;
setState(() {
driversList = data;
isLoading = false;
});
} catch (e) {
debugPrint("⚠️ Error fetching drivers: $e");
setState(() => isLoading = false);
}
}
// Validators
String? _required(String? v, {String field = "This field"}) { String? _required(String? v, {String field = "This field"}) {
if (v == null || v.trim().isEmpty) return "$field is required"; if (v == null || v.trim().isEmpty) return "$field is required";
return null; return null;
@ -49,22 +76,6 @@ class _FleetEmployeesState extends State<FleetEmployees> {
return null; return null;
} }
@override
void dispose() {
_nameCtrl.dispose();
_mobileCtrl.dispose();
_altMobileCtrl.dispose();
super.dispose();
}
Map<String, dynamic> _buildPayload() => {
"driver_name": _nameCtrl.text.trim(),
"license_number": selectedLicense,
"experience_years": selectedExperience,
"phone": _mobileCtrl.text.trim(),
"alt_phone": _altMobileCtrl.text.trim(),
};
void _clearForm() { void _clearForm() {
_nameCtrl.clear(); _nameCtrl.clear();
_mobileCtrl.clear(); _mobileCtrl.clear();
@ -74,51 +85,42 @@ class _FleetEmployeesState extends State<FleetEmployees> {
setState(() {}); setState(() {});
} }
void _addDriver() async{ Future<void> _addDriver() async {
final ok = _formKey.currentState?.validate() ?? false; if (!(_formKey.currentState?.validate() ?? false)) return;
setState(() {}); // ensure error texts render if (selectedLicense == null || selectedExperience == null) {
if (!ok || AppSettings.longFailedToast("Select License & Experience");
selectedLicense == null ||
selectedExperience == null ||
selectedExperience!.isEmpty) {
if (selectedExperience == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Please select License & Experience")),
);
}
return; return;
} }
var payload = new Map<String, dynamic>();
payload["Name"] = _nameCtrl.text.toString();
payload["license_number"] =selectedLicense.toString();
payload["address"] = AppSettings.userAddress;
payload["supplier_name"] = AppSettings.userName;
payload["phone"] = _mobileCtrl.text.toString();
payload["alternativeContactNumber"] ='';
payload["years_of_experience"] =selectedExperience.toString();
payload["status"] = 'string';
var payload = {
"Name": _nameCtrl.text.trim(),
"license_number": selectedLicense,
"address": AppSettings.userAddress,
"supplier_name": AppSettings.userName,
"phone": _mobileCtrl.text.trim(),
"alternativeContactNumber": _altMobileCtrl.text.trim(),
"years_of_experience": selectedExperience,
"status": "active",
};
bool tankStatus = await AppSettings.addDrivers(payload); bool status = await AppSettings.addDrivers(payload);
if (status) {
try { AppSettings.longSuccessToast("Driver Added Successfully");
if (tankStatus) { _clearForm();
AppSettings.longSuccessToast("Tanker Created Successfully"); Navigator.pop(context, true);
_nameCtrl.text = ''; _fetchDrivers();
Navigator.pop(context,true); } else {
AppSettings.longFailedToast("Failed to add driver");
} }
else {
AppSettings.longFailedToast("Tanker Creation failed");
} }
} catch (exception) {
print(exception); void _onContinue() {
if (currentStep < 5) {
setState(() => currentStep += 1);
} else {
// You can navigate to next screen here
// Navigator.push(context, MaterialPageRoute(builder: (_) => const NextScreen()));
} }
_clearForm();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Driver added (${_drivers.length})")),
);
} }
@override @override
@ -132,305 +134,353 @@ class _FleetEmployeesState extends State<FleetEmployees> {
scrolledUnderElevation: 0, scrolledUnderElevation: 0,
title: const Text("Complete Profile"), title: const Text("Complete Profile"),
actions: [ actions: [
Padding( IconButton(
padding: const EdgeInsets.fromLTRB(10, 10, 0, 10),
child: IconButton(
splashRadius: 20, splashRadius: 20,
padding: EdgeInsets.zero, icon: const Image(
icon: const Image(image: AssetImage('images/calendar_appbar.png'), width: 22, height: 22), image: AssetImage('images/calendar_appbar.png'),
onPressed: () {}, width: 22,
height: 22,
), ),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 10, 10),
child: IconButton(
splashRadius: 20,
padding: EdgeInsets.zero,
icon: Image.asset('images/notification_appbar.png', width: 22, height: 22),
onPressed: () {}, onPressed: () {},
), ),
IconButton(
splashRadius: 20,
icon: Image.asset('images/notification_appbar.png',
width: 22, height: 22),
onPressed: () {
},
), ),
], ],
), ),
body: SafeArea( body: SafeArea(
child: Form( child: isLoading
key: _formKey, ? const Center(child: CircularProgressIndicator())
child: ListView( : Column(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 24), crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Step indicator // Header
Padding(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Step $currentStep/5",),
Row(
children: List.generate(5, (index) {
final isFilled = index < currentStep;
return Expanded(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2),
height: 5,
decoration: BoxDecoration(
color: isFilled ? const Color(0xFF0D3771) : const Color(0xFFE6E6E6),
borderRadius: BorderRadius.circular(2),
),
),
);
}),
),
const SizedBox(height: 16),
Text("EMPLOYEES",
style: fontTextStyle(20, Color(0xFF515253), FontWeight.w600)),
const SizedBox(height: 8),
Image.asset('images/manage-users.png', width: 24, height: 24),
const SizedBox(height: 8),
Text( Text(
"Step 1/5", "Details about your driver fleet",
style: fontTextStyle(16, const Color(0xFFC3C4C4), FontWeight.w500), style: fontTextStyle(14, Color(0xFF939495), FontWeight.w500),
),
],
),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
// Header block // Driver list
Column( Expanded(
child: driversList.isEmpty
? Center(
child: Text(
"No drivers added yet.",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400),
),
)
: ListView.separated(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 100),
itemCount: driversList.length,
separatorBuilder: (_, __) => const SizedBox(height: 8),
itemBuilder: (context, idx) {
final d = driversList[idx];
bool expanded = false;
return StatefulBuilder(
builder: (context, setInnerState) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 0),
decoration: BoxDecoration(
color: Color(0xFFF1F1F1), // background color
border: Border.all(color: Color(0xFFE5E5E5)),
borderRadius: BorderRadius.circular(29),
),
child: Column(
children: [
ListTile(
dense: true, // makes tile shorter
contentPadding: EdgeInsets.zero, // removes default horizontal padding
minVerticalPadding: 0,
visualDensity: const VisualDensity(vertical: -4, horizontal: 0),
title: Text(
d.driver_name ?? 'Unnamed Driver',
style: fontTextStyle(14, const Color(0xFF2D2E30), FontWeight.w600),
),
trailing: IconButton(
padding: EdgeInsets.zero,
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
icon: Image.asset(
expanded ? 'images/arrow-up.png' : 'images/downarrow.png',
width: 18,
height: 18,
),
onPressed: () => setInnerState(() {
expanded = !expanded;
}),
),
),
if (expanded)
Align(
alignment: Alignment.centerLeft,
child: Container(
margin: const EdgeInsets.only(left: 10, right: 10, bottom: 6),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: Color(0xFFFFFFFF), // 👈 white background
border: Border.all(color:Color(0xFFFFFFFF)), // light border
borderRadius: BorderRadius.circular(8), // smooth rounded edges
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text("EMPLOYEES", style: fontTextStyle(20, const Color(0xFF515253), FontWeight.w600)), Text(
const SizedBox(height: 8), "${d.address ?? 'N/A'} : " " ${d.phone_number ?? 'N/A'}",
Container( style: fontTextStyle(12, const Color(0xFF2D2E30), FontWeight.w500),
width: 24,
height: 24,
decoration: const BoxDecoration(
image: DecorationImage(image: AssetImage('images/manage-users.png'), fit: BoxFit.contain),
), ),
const SizedBox(height: 4),
],
),
),
), ],
),
);
},
);
},
), ),
)
], ],
), ),
const SizedBox(height: 6),
Text(
"Details about your water tanker fleet",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w500),
), ),
const SizedBox(height: 16),
// Section header (just the bar) // Bottom buttons
_SectionHeaderBar( bottomSheet: Container(
title: "DRIVER #1", color: Colors.white,
icon: Image.asset('images/arrow-up.png', width: 16, height: 16), padding:
radius: 20, const EdgeInsets.symmetric(horizontal: 20).copyWith(bottom: 24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () {
_openAddDriverSheet(context);
},
icon: Image.asset('images/Add_icon.png',
width: 16, height: 16),
label: Text(
"Add Driver",
style: fontTextStyle(
14, const Color(0xFF646566), FontWeight.w600),
),
),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF8270DB),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24)),
),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => const SourceLocation()));
},
child: Text(
"Continue",
style: fontTextStyle(14, Colors.white, FontWeight.w400),
),
),
),
],
),
),
);
}
// === Fields // Bottom sheet for Add Driver form
void _openAddDriverSheet(BuildContext context) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
),
builder: (_) {
return Padding(
padding:
MediaQuery.of(context).viewInsets.add(const EdgeInsets.all(20)),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text("Add New Driver",
style: fontTextStyle(
18, const Color(0xFF2D2E30), FontWeight.w600)),
const SizedBox(height: 16),
_LabeledField( _LabeledField(
label: "Driver Name *", label: "Driver Name *",
child: TextFormField( child: TextFormField(
controller: _nameCtrl, controller: _nameCtrl,
validator: (v) => _required(v, field: "Driver Name"), validator: (v) => _required(v, field: "Driver Name"),
textCapitalization: TextCapitalization.none,
inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps
],
decoration: const InputDecoration( decoration: const InputDecoration(
hintText: "Full Name", hintText: "Full Name",
border: OutlineInputBorder(), border: OutlineInputBorder(),
isDense: true, isDense: true,
), ),
textInputAction: TextInputAction.next,
), ),
), ),
_LabeledField( _LabeledField(
label: "Driver License Number *", label: "License Number *",
child: DropdownButtonFormField<String>( child: DropdownButtonFormField<String>(
value: selectedLicense, value: selectedLicense,
items: licenseNumbers items: licenseNumbers
.map((t) => DropdownMenuItem(value: t, child: Text(t))) .map((t) =>
DropdownMenuItem(value: t, child: Text(t)))
.toList(), .toList(),
onChanged: (v) => setState(() => selectedLicense = v), onChanged: (v) => setState(() => selectedLicense = v),
validator: (v) => v == null || v.isEmpty ? "Driver License required" : null, validator: (v) => v == null ? "Select License" : null,
isExpanded: true,
alignment: Alignment.centerLeft,
hint: Text(
"Select License Number",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png', width: 16, height: 16),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
isDense: false, isDense: true,
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
), ),
), ),
), ),
_LabeledField( _LabeledField(
label: "Years of Experience *", label: "Years of Experience *",
child: DropdownButtonFormField<String>( child: DropdownButtonFormField<String>(
value: selectedExperience, value: selectedExperience,
items: yearOptions items: yearOptions
.map((t) => DropdownMenuItem(value: t, child: Text(t))) .map((t) =>
DropdownMenuItem(value: t, child: Text(t)))
.toList(), .toList(),
onChanged: (v) => setState(() => selectedExperience = v), onChanged: (v) => setState(() => selectedExperience = v),
validator: (v) => v == null || v.isEmpty ? "Experience is required" : null, validator: (v) =>
isExpanded: true, v == null ? "Select Experience" : null,
alignment: Alignment.centerLeft,
hint: Text(
"Years",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png', width: 16, height: 16),
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
isDense: false, isDense: true,
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
), ),
), ),
), ),
_LabeledField( _LabeledField(
label: "Phone Number *", label: "Phone Number *",
child: TextFormField( child: TextFormField(
controller: _mobileCtrl, controller: _mobileCtrl,
validator: (v) => _validatePhone(v, label: "Phone Number"), validator: (v) => _validatePhone(v),
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10), LengthLimitingTextInputFormatter(10),
], ],
decoration: InputDecoration( decoration: const InputDecoration(
hintText: "Mobile Number", hintText: "Mobile Number",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), border: OutlineInputBorder(),
border: const OutlineInputBorder(),
isDense: true, isDense: true,
), ),
textInputAction: TextInputAction.next,
), ),
), ),
_LabeledField( _LabeledField(
label: "Alternate Phone Number", label: "Alternate Phone Number",
child: TextFormField( child: TextFormField(
controller: _altMobileCtrl, controller: _altMobileCtrl,
validator: (v) {
if (v == null || v.trim().isEmpty) return null; // optional
return _validatePhone(v, label: "Alternate Phone Number");
},
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10), LengthLimitingTextInputFormatter(10),
], ],
decoration: InputDecoration( decoration: const InputDecoration(
hintText: "Mobile Number", hintText: "Mobile Number",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), border: OutlineInputBorder(),
border: const OutlineInputBorder(),
isDense: true, isDense: true,
), ),
textInputAction: TextInputAction.next,
), ),
), ),
const SizedBox(height: 16),
const SizedBox(height: 20), ElevatedButton(
// Actions
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: _addDriver, onPressed: _addDriver,
icon: Image.asset('images/Add_icon.png', width: 16, height: 16),
label: Text(
"Add Driver",
style: fontTextStyle(14, const Color(0xFF646566), FontWeight.w600),
),
),
),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF8270DB), backgroundColor: const Color(0xFF0D3771),
foregroundColor: Colors.white, foregroundColor: Colors.white),
padding: const EdgeInsets.symmetric(vertical: 14), child: const Text("Add Driver"),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
),
onPressed: () {
// // TODO: Navigate to the next step/screen
// Navigator.push(context, MaterialPageRoute(builder: (_) => const SourceLocation()));
// // ScaffoldMessenger.of(context).showSnackBar(
// // SnackBar(content: Text("Saved ${_drivers.length} driver(s). Proceeding…")),
// // );
},
child: Text(
"Continue",
style: fontTextStyle(14, Colors.white, FontWeight.w400),
),
),
),
],
), ),
], ],
), ),
), ),
), ),
); );
} },
}
// ======= UI helpers =======
class _SectionHeaderBar extends StatelessWidget {
final String title;
final Widget? icon;
final Color backgroundColor;
final Color borderColor;
final double radius;
const _SectionHeaderBar({
required this.title,
this.icon,
this.backgroundColor = const Color(0xFFEEEEEE),
this.borderColor = const Color(0xFFE5E7EB),
this.radius = 12,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: backgroundColor,
border: Border.all(color: borderColor, width: 1),
borderRadius: BorderRadius.circular(radius),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 6,
offset: const Offset(0, 2),
),
],
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
child: Row(
children: [
Expanded(
child: Text(
title,
style: fontTextStyle(12, const Color(0xFF2D2E30), FontWeight.w600),
),
),
if (icon != null) icon!,
],
),
); );
} }
} }
// ============ UI Helper ==============
class _LabeledField extends StatelessWidget { class _LabeledField extends StatelessWidget {
final String label; final String label;
final Widget child; final Widget child;
final String? Function()? validator; // (kept from your earlier helper; not used here)
const _LabeledField({ const _LabeledField({required this.label, required this.child});
required this.label,
required this.child,
this.validator,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final errorText = validator != null ? validator!() : null;
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 14.0), padding: const EdgeInsets.only(bottom: 14),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(label, style: fontTextStyle(12, const Color(0xFF515253), FontWeight.w600)), Text(label,
style:
fontTextStyle(12, const Color(0xFF515253), FontWeight.w600)),
const SizedBox(height: 6), const SizedBox(height: 6),
child, child,
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
),
),
], ],
), ),
); );

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:supplier_new/common/settings.dart'; import 'package:supplier_new/common/settings.dart';
import '../resources/resources_drivers.dart';
import 'employees.dart'; import 'employees.dart';
class FleetStep1Page extends StatefulWidget { class FleetStep1Page extends StatefulWidget {
@ -16,6 +17,8 @@ class _FleetStep1PageState extends State<FleetStep1Page> {
bool isLoading = false; bool isLoading = false;
List<dynamic> tankersList = []; List<dynamic> tankersList = [];
String search = ''; String search = '';
int currentStep = 1; // 1..5
@override @override
void initState() { void initState() {
@ -43,6 +46,7 @@ class _FleetStep1PageState extends State<FleetStep1Page> {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
isScrollControlled: true, isScrollControlled: true,
backgroundColor: Color(0xFFFFFFFF),
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(24)), borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
), ),
@ -98,9 +102,24 @@ class _FleetStep1PageState extends State<FleetStep1Page> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text("Step 2/5", Text("Step 1/5",
style: fontTextStyle(16, Color(0xFFC3C4C4), FontWeight.w500)), style: fontTextStyle(16, Color(0xFFC3C4C4), FontWeight.w500)),
const SizedBox(height: 16), const SizedBox(height: 16),
Row(
children: List.generate(5, (index) {
return Expanded(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2),
height: 5,
decoration: BoxDecoration(
color: index < 5 ? const Color(0xFFC3C4C4) : Colors.grey,
borderRadius: BorderRadius.circular(2),
),
),
);
}),
),
const SizedBox(height: 16),
Text("FLEET", Text("FLEET",
style: fontTextStyle(20, Color(0xFF515253), FontWeight.w600)), style: fontTextStyle(20, Color(0xFF515253), FontWeight.w600)),
const SizedBox(height: 8), const SizedBox(height: 8),
@ -313,7 +332,10 @@ class _AddTankerFormState extends State<AddTankerForm> {
AppSettings.longFailedToast("Tanker Creation Failed"); AppSettings.longFailedToast("Tanker Creation Failed");
} }
} }
String? _required(String? v, {String field = "This field"}) {
if (v == null || v.trim().isEmpty) return "$field is required";
return null;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
@ -333,24 +355,40 @@ class _AddTankerFormState extends State<AddTankerForm> {
label: "Tanker Name *", label: "Tanker Name *",
child: TextFormField( child: TextFormField(
controller: _nameCtrl, controller: _nameCtrl,
validator: (v) => v == null || v.isEmpty ? "Required" : null, validator: (v) => _required(v, field: "Tanker Name"),
decoration: textCapitalization: TextCapitalization.none,
const InputDecoration(border: OutlineInputBorder(), isDense: true), inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps
],
decoration: InputDecoration(
hintText: "Enter Tanker Name",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
border: const OutlineInputBorder(),
isDense: true,
), ),
textInputAction: TextInputAction.next,
), ),
),
_LabeledField( _LabeledField(
label: "Capacity (in L) *", label: "Tanker Capacity (in L) *",
child: TextFormField( child: TextFormField(
controller: _capacityCtrl, controller: _capacityCtrl,
validator: (v) => v == null || v.isEmpty ? "Required" : null, validator: (v) => _required(v, field: "Tanker Capacity"),
decoration: InputDecoration(
hintText: "10,000",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
border: const OutlineInputBorder(),
isDense: true,
),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'[0-9,]')) FilteringTextInputFormatter.allow(RegExp(r'[0-9,]')),
], ],
decoration: textInputAction: TextInputAction.next,
const InputDecoration(border: OutlineInputBorder(), isDense: true),
), ),
), ),
_LabeledField( _LabeledField(
label: "Tanker Type *", label: "Tanker Type *",
child: DropdownButtonFormField<String>( child: DropdownButtonFormField<String>(
@ -359,55 +397,94 @@ class _AddTankerFormState extends State<AddTankerForm> {
.map((t) => DropdownMenuItem(value: t, child: Text(t))) .map((t) => DropdownMenuItem(value: t, child: Text(t)))
.toList(), .toList(),
onChanged: (v) => setState(() => selectedType = v), onChanged: (v) => setState(() => selectedType = v),
validator: (v) => v == null ? "Required" : null, validator: (v) => v == null || v.isEmpty ? "Tanker Type is required" : null,
decoration: isExpanded: true,
const InputDecoration(border: OutlineInputBorder(), isDense: true), alignment: Alignment.centerLeft,
hint: Text(
"Select Type",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png', width: 16, height: 16),
decoration: const InputDecoration(
border: OutlineInputBorder(),
isDense: false,
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
),
), ),
), ),
_LabeledField( _LabeledField(
label: "Type of Water *", label: "Type of water *",
child: DropdownButtonFormField<String>( child: DropdownButtonFormField<String>(
value: selectedTypeOfWater, value: selectedTypeOfWater,
items: typeOfWater items: typeOfWater
.map((t) => DropdownMenuItem(value: t, child: Text(t))) .map((t) => DropdownMenuItem(value: t, child: Text(t)))
.toList(), .toList(),
onChanged: (v) => setState(() => selectedTypeOfWater = v), onChanged: (v) => setState(() => selectedTypeOfWater = v),
validator: (v) => v == null ? "Required" : null, validator: (v) => v == null || v.isEmpty ? "Type of water is required" : null,
decoration: isExpanded: true,
const InputDecoration(border: OutlineInputBorder(), isDense: true), alignment: Alignment.centerLeft,
hint: Text(
"Select type of water",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
),
icon: Image.asset('images/downarrow.png', width: 16, height: 16),
decoration: const InputDecoration(
border: OutlineInputBorder(),
isDense: false,
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
), ),
), ),
),
_LabeledField( _LabeledField(
label: "License Plate *", label: "License Plate *",
child: TextFormField( child: TextFormField(
controller: _plateCtrl, controller: _plateCtrl,
validator: (v) => v == null || v.isEmpty ? "Required" : null, validator: (v) => _required(v, field: "License Plate"),
decoration: InputDecoration(
hintText: "AB 05 H 4948",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
border: const OutlineInputBorder(),
isDense: true,
),
textCapitalization: TextCapitalization.characters, textCapitalization: TextCapitalization.characters,
decoration: textInputAction: TextInputAction.next,
const InputDecoration(border: OutlineInputBorder(), isDense: true),
), ),
), ),
_LabeledField( _LabeledField(
label: "Manufacturing Year", label: "Manufacturing Year (opt)",
child: TextFormField( child: TextFormField(
controller: _mfgYearCtrl, controller: _mfgYearCtrl,
decoration: InputDecoration(
hintText: "YYYY",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
border: const OutlineInputBorder(),
isDense: true,
),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(4) LengthLimitingTextInputFormatter(4),
], ],
decoration: textInputAction: TextInputAction.next,
const InputDecoration(border: OutlineInputBorder(), isDense: true),
), ),
), ),
_LabeledField( _LabeledField(
label: "Insurance Expiry Date", label: "Insurance Expiry Date (opt)",
child: TextFormField( child: TextFormField(
controller: _insExpiryCtrl, controller: _insExpiryCtrl,
readOnly: true, readOnly: true,
decoration: InputDecoration(
hintText: "DD-MM-YYYY",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
border: const OutlineInputBorder(),
isDense: true,
suffixIcon: const Icon(Icons.calendar_today_outlined, size: 18),
),
onTap: _pickInsuranceDate, onTap: _pickInsuranceDate,
decoration:
const InputDecoration(border: OutlineInputBorder(), isDense: true),
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),

@ -1,5 +1,5 @@
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
@ -8,12 +8,12 @@ import '../common/keys.dart';
import '../google_maps_place_picker_mb/src/models/pick_result.dart'; import '../google_maps_place_picker_mb/src/models/pick_result.dart';
import '../google_maps_place_picker_mb/src/place_picker.dart'; import '../google_maps_place_picker_mb/src/place_picker.dart';
import 'package:supplier_new/google_maps_place_picker_mb/google_maps_place_picker.dart'; import 'package:supplier_new/google_maps_place_picker_mb/google_maps_place_picker.dart';
import 'dart:io' show File, Platform;
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart'; import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:location/location.dart' as locationmap; import 'package:location/location.dart' as locationmap;
import '../resources/resources_drivers.dart';
import '../resources/source_loctaions_model.dart';
void main() => runApp(const MaterialApp(home: SourceLocation()));
class SourceLocation extends StatefulWidget { class SourceLocation extends StatefulWidget {
const SourceLocation({super.key}); const SourceLocation({super.key});
@ -22,36 +22,19 @@ class SourceLocation extends StatefulWidget {
State<SourceLocation> createState() => _SourceLocationState(); State<SourceLocation> createState() => _SourceLocationState();
} }
class _SourceLocationState extends State<SourceLocation> { PickResult? selectedPlace;
final _formKey = GlobalKey<FormState>();
// Controllers
final _locationNameController = TextEditingController();
final _mobileCtrl = TextEditingController();
String address='';
String address1 = '';
String address2 = '';
String city = '';
String state = '';
String zip = '';
String country = '';
double lat=0;
double lng=0;
PickResult? selectedPlace; bool _mapsInitialized = false;
final String _mapsRenderer = "latest";
bool _mapsInitialized = false; var kInitialPosition = const LatLng(15.462477, 78.717401);
final String _mapsRenderer = "latest";
var kInitialPosition = const LatLng(15.462477, 78.717401); locationmap.Location location = locationmap.Location();
locationmap.Location location = locationmap.Location(); final GoogleMapsFlutterPlatform mapsImplementation =
final GoogleMapsFlutterPlatform mapsImplementation =
GoogleMapsFlutterPlatform.instance; GoogleMapsFlutterPlatform.instance;
void initRenderer() { void initRenderer() {
if (_mapsInitialized) return; if (_mapsInitialized) return;
if (mapsImplementation is GoogleMapsFlutterAndroid) { if (mapsImplementation is GoogleMapsFlutterAndroid) {
switch (_mapsRenderer) { switch (_mapsRenderer) {
@ -65,13 +48,18 @@ class _SourceLocationState extends State<SourceLocation> {
break; break;
} }
} }
setState(() { // setState(() {
_mapsInitialized = true; // _mapsInitialized = true;
}); // });
} }
class _SourceLocationState extends State<SourceLocation> {
bool isLoading = false;
int currentStep = 2;
List<SourceLocationsModel> sourceLocationsList = [];
final _locationNameController = TextEditingController();
bool addBusinessAsSource = false;
// Dropdowns
final List<String> waterTypes = [ final List<String> waterTypes = [
"Drinking Water", "Drinking Water",
"Bore Water", "Bore Water",
@ -79,228 +67,125 @@ class _SourceLocationState extends State<SourceLocation> {
"Construction", "Construction",
"Non-potable", "Non-potable",
]; ];
String? selectedWaterType;
// Data bucket // For map
final List<Map<String, dynamic>> _drivers = []; bool _mapsInitialized = false;
final GoogleMapsFlutterPlatform mapsImplementation =
// Validators GoogleMapsFlutterPlatform.instance;
String? _required(String? v, {String field = "This field"}) { final locationmap.Location location = locationmap.Location();
if (v == null || v.trim().isEmpty) return "$field is required"; var kInitialPosition = const LatLng(15.462477, 78.717401);
return null;
}
String? _validatePhone(String? v, {String label = "Phone Number"}) { void initRenderer() {
if (v == null || v.trim().isEmpty) return "$label is required"; if (_mapsInitialized) return;
final digits = v.replaceAll(RegExp(r'\D'), ''); if (mapsImplementation is GoogleMapsFlutterAndroid) {
if (digits.length != 10) return "Enter a 10-digit $label"; (mapsImplementation as GoogleMapsFlutterAndroid)
if (!RegExp(r'^[6-9]\d{9}$').hasMatch(digits)) { .initializeWithRenderer(AndroidMapRenderer.latest);
return "$label must start with 6/7/8/9";
} }
return null; setState(() => _mapsInitialized = true);
} }
@override
void dispose() {
_locationNameController.dispose();
_mobileCtrl.dispose();
super.dispose();
}
bool addBusinessAsSource = false;
void _clearForm() { @override
_locationNameController.clear(); void initState() {
_mobileCtrl.clear(); super.initState();
selectedWaterType = null; _fetchSources();
setState(() {});
} }
void _addSourceLocation() async{ Future<void> _fetchSources() async {
final ok = _formKey.currentState?.validate() ?? false; setState(() => isLoading = true);
try {
if(addBusinessAsSource){ final response = await AppSettings.getSourceLoctaions();
final data = (jsonDecode(response)['data'] as List)
.map((e) => SourceLocationsModel.fromJson(e))
.toList();
if (!mounted) return;
setState(() { setState(() {
address=AppSettings.userAddress; sourceLocationsList = data;
lat=AppSettings.supplierLatitude; isLoading = false;
lng=AppSettings.supplierLongitude;
}); });
} catch (e) {
debugPrint("⚠️ Error fetching source locations: $e");
setState(() => isLoading = false);
} }
setState(() {}); // ensure error texts render
if (!ok ||
selectedWaterType == null ||
selectedWaterType!.isEmpty) {
if (selectedWaterType == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Please select Water type")),
);
}
return;
} }
var payload = new Map<String, dynamic>(); String? _required(String? v, {String field = "This field"}) {
payload["location_name"] = _locationNameController.text.toString(); if (v == null || v.trim().isEmpty) return "$field is required";
payload["phone"] = _mobileCtrl.text.toString(); return null;
payload["water_type"] =selectedWaterType.toString();
payload["status"] ='string';
payload["address"] = address;
payload["city"] = '';
payload["state"] = '';
payload["zip"] ='';
payload["latitude"] = lat;
payload["longitude"] = lng;
bool tankStatus = await AppSettings.addSourceLocations(payload);
try {
if (tankStatus) {
AppSettings.longSuccessToast("Source location added Successfully");
_locationNameController.text = '';
Navigator.pop(context,true);
}
else {
AppSettings.longFailedToast("Tanker Creation failed");
}
} catch (exception) {
print(exception);
} }
_clearForm(); String? _validatePhone(String? v, {String label = "Phone"}) {
ScaffoldMessenger.of(context).showSnackBar( if (v == null || v.trim().isEmpty) return "$label is required";
SnackBar(content: Text("Driver added (${_drivers.length})")), if (v.trim().length != 10) return "$label must be 10 digits";
); return null;
} }
void _showAddLocationSheet() {
final _formKey = GlobalKey<FormState>();
final TextEditingController _nameCtrl = TextEditingController();
final TextEditingController _mobileCtrl = TextEditingController();
String? selectedWaterType;
String address = '';
double lat = 0;
double lng = 0;
@override showModalBottomSheet(
Widget build(BuildContext context) { isScrollControlled: true,
return Scaffold( context: context,
backgroundColor: Colors.white, shape: const RoundedRectangleBorder(
appBar: AppBar( borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
backgroundColor: Colors.white, backgroundColor: Colors.white,
surfaceTintColor: Colors.transparent, builder: (context) {
elevation: 0, return Padding(
scrolledUnderElevation: 0, padding: EdgeInsets.only(
title: const Text("Complete Profile"), left: 20,
actions: [ right: 20,
Padding( top: 20,
padding: const EdgeInsets.fromLTRB(10, 10, 0, 10), bottom: MediaQuery.of(context).viewInsets.bottom + 20,
child: IconButton(
splashRadius: 20,
padding: EdgeInsets.zero,
icon: const Image(image: AssetImage('images/calendar_appbar.png'), width: 22, height: 22),
onPressed: () {},
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 10, 10),
child: IconButton(
splashRadius: 20,
padding: EdgeInsets.zero,
icon: Image.asset('images/notification_appbar.png', width: 22, height: 22),
onPressed: () {},
),
),
],
), ),
body: SafeArea( child: SingleChildScrollView(
child: Form( child: Form(
key: _formKey, key: _formKey,
child: ListView( child: Column(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 24), crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [ children: [
// Step indicator Center(
Text(
"Step 3/5",
style: fontTextStyle(16, const Color(0xFFC3C4C4), FontWeight.w500),
),
const SizedBox(height: 16),
Row(
children: List.generate(4, (index) {
return Expanded(
child: Container( child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2), width: 40,
height: 5, height: 4,
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration( decoration: BoxDecoration(
color: index < 4 ? const Color(0xFFC3C4C4) : Colors.grey, color: Colors.grey[300],
borderRadius: BorderRadius.circular(2), borderRadius: BorderRadius.circular(2),
), ),
), ),
);
}),
),
const SizedBox(height: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("SORURCE LOCATION", style: fontTextStyle(20, const Color(0xFF515253), FontWeight.w600)),
const SizedBox(height: 8),
Container(
width: 24,
height: 24,
decoration: const BoxDecoration(
image: DecorationImage(image: AssetImage('images/flag.png'), fit: BoxFit.contain),
),
),
],
),
const SizedBox(height: 6),
Text(
"Add your source Location",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w500),
), ),
const SizedBox(height: 6), Center(
Align( child: Text(
alignment: Alignment.centerLeft, // keep the whole thing on the left "Add Source Location",
child: Row( style: fontTextStyle(
mainAxisSize: MainAxisSize.min, // don't stretch full width 16, const Color(0xFF2D2E30), FontWeight.w600),
children: [
Checkbox(
value: addBusinessAsSource,
onChanged: (v) => setState(() => addBusinessAsSource = v ?? false),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
),
const SizedBox(width: 6), // control the exact gap
Text(
"Add Business Location as a Source Location",
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w500),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
), ),
), ),
const SizedBox(height: 20),
const SizedBox(height: 16),
// Section header (just the bar)
_SectionHeaderBar(
title: "SOURCE LOCATION #1",
icon: Image.asset('images/arrow-up.png', width: 16, height: 16),
radius: 20,
),
const SizedBox(height: 12),
// === Fields
_LabeledField( _LabeledField(
label: "Location Name *", label: "Location Name *",
child: TextFormField( child: TextFormField(
controller: _locationNameController, controller: _locationNameController,
validator: (v) => _required(v, field: "Location Name"), validator: (v) => _required(v, field: "Location Name"),
textCapitalization: TextCapitalization.none,
inputFormatters: const [
FirstCharUppercaseFormatter(), // << live first-letter caps
],
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Location Name", hintText: "Location Name",
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
border: OutlineInputBorder(), border: const OutlineInputBorder(),
isDense: true, isDense: true,
), ),
textInputAction: TextInputAction.next, textInputAction: TextInputAction.next,
), ),
), ),
_LabeledField( _LabeledField(
label: "Mobile Number *", label: "Mobile Number *",
child: TextFormField( child: TextFormField(
@ -320,6 +205,7 @@ class _SourceLocationState extends State<SourceLocation> {
textInputAction: TextInputAction.next, textInputAction: TextInputAction.next,
), ),
), ),
Visibility( Visibility(
visible: !addBusinessAsSource, visible: !addBusinessAsSource,
child: Column( child: Column(
@ -328,97 +214,7 @@ class _SourceLocationState extends State<SourceLocation> {
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
child: OutlinedButton.icon( child: OutlinedButton.icon(
onPressed: (){
location.serviceEnabled().then((value) {
if (value) {
initRenderer();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return PlacePicker(
resizeToAvoidBottomInset: false,
hintText: "Find a place ...",
searchingText: "Please wait ...",
selectText: "Select place",
outsideOfPickAreaText: "Place not in area",
initialPosition: kInitialPosition,
useCurrentLocation: true,
selectInitialPosition: true,
usePinPointingSearch: true,
usePlaceDetailSearch: true,
zoomGesturesEnabled: true,
zoomControlsEnabled: true,
onMapCreated: (GoogleMapController controller) {},
onPlacePicked: (PickResult result) {
setState(() {
selectedPlace = result;
lat=selectedPlace!.geometry!.location.lat;
lng=selectedPlace!.geometry!.location.lng;
if(selectedPlace!.types!.length==1){
address =
selectedPlace!.formattedAddress!;
}
else{
address =selectedPlace!.name!+', '+selectedPlace!.formattedAddress!;
}
Navigator.of(context).pop();
});
},
onMapTypeChanged: (MapType mapType) {},
apiKey: Platform.isAndroid
? APIKeys.androidApiKey
: APIKeys.iosApiKey,
forceAndroidLocationManager: true,
);
},
),
);
} else {
showGeneralDialog(
context: context,
pageBuilder: (context, x, y) {
return Scaffold(
backgroundColor: Colors.grey.withOpacity(.5),
body: Center(
child: Container(
width: double.infinity,
height: 150,
padding:
const EdgeInsets.symmetric(horizontal: 20),
child: Card(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"Please enable the location",
style: TextStyle(
fontSize:18,
fontWeight: FontWeight.w500,
),
),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () { onPressed: () {
Navigator.pop(context);
},
child: const Text("Cancel"),
),
],
),
),
),
),
),
);
},
);
}
});
}, },
icon: Image.asset('images/Add_icon.png', width: 16, height: 16), icon: Image.asset('images/Add_icon.png', width: 16, height: 16),
label: Text( label: Text(
@ -428,9 +224,10 @@ class _SourceLocationState extends State<SourceLocation> {
), ),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
], ],
),), ),
),
_LabeledField( _LabeledField(
label: "Water Type *", label: "Water Type *",
child: DropdownButtonFormField<String>( child: DropdownButtonFormField<String>(
@ -455,138 +252,205 @@ class _SourceLocationState extends State<SourceLocation> {
), ),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
const SizedBox(height: 20),
// Actions
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: _addSourceLocation,
icon: Image.asset('images/Add_icon.png', width: 16, height: 16),
label: Text(
"Add Location",
style: fontTextStyle(14, const Color(0xFF646566), FontWeight.w600),
),
),
),
const SizedBox(height: 12),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
child: ElevatedButton( child: ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF8270DB), backgroundColor: const Color(0xFF8270DB),
foregroundColor: Colors.white, shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24)),
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
), ),
onPressed: () { onPressed: () async {
// // TODO: Navigate to the next step/screen if (_formKey.currentState?.validate() ?? false) {
// Navigator.push(context, MaterialPageRoute(builder: (_) => const SourceLocation1())); var payload = {
// // ScaffoldMessenger.of(context).showSnackBar( "location_name": _nameCtrl.text,
// // SnackBar(content: Text("Saved ${_drivers.length} driver(s). Proceeding…")), "phone": _mobileCtrl.text,
// // ); "water_type": selectedWaterType,
"address": address,
"latitude": lat,
"longitude": lng,
"status": "active",
};
bool ok =
await AppSettings.addSourceLocations(payload);
if (ok) {
AppSettings.longSuccessToast(
"Source added successfully");
Navigator.pop(context);
_fetchSources();
} else {
AppSettings.longFailedToast(
"Failed to add location");
}
}
}, },
child: const Text("Save Location",
child: Text( style: TextStyle(
"Continue", fontSize: 14, color: Colors.white)),
style: fontTextStyle(14, Colors.white, FontWeight.w400),
),
),
), ),
],
), ),
], ],
), ),
), ),
), ),
); );
},
);
} }
}
// ======= UI helpers =======
class _SectionHeaderBar extends StatelessWidget {
final String title;
final Widget? icon;
final Color backgroundColor;
final Color borderColor;
final double radius;
const _SectionHeaderBar({
required this.title,
this.icon,
this.backgroundColor = const Color(0xFFEEEEEE),
this.borderColor = const Color(0xFFE5E7EB),
this.radius = 12,
Key? key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
surfaceTintColor: Colors.transparent,
elevation: 0,
title: const Text("Complete Profile"),
),
body: SafeArea(
child: isLoading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 24),
children: [
Text("Step $currentStep/5",
style: fontTextStyle(
16, const Color(0xFFC3C4C4), FontWeight.w500)),
const SizedBox(height: 16),
Text("SOURCE LOCATION",
style: fontTextStyle(
20, const Color(0xFF515253), FontWeight.w600)),
const SizedBox(height: 6),
Text("Add your source location",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w500)),
const SizedBox(height: 16),
// List of saved locations
if (sourceLocationsList.isEmpty)
const Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: Center(
child: Text("No source locations added yet."),
),
)
else
...List.generate(sourceLocationsList.length, (idx) {
final d = sourceLocationsList[idx];
bool expanded = false;
return StatefulBuilder(builder: (context, setInner) {
return Container( return Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 6),
decoration: BoxDecoration( decoration: BoxDecoration(
color: backgroundColor, color: const Color(0xFFF1F1F1),
border: Border.all(color: borderColor, width: 1), border: Border.all(color: const Color(0xFFE5E5E5)),
borderRadius: BorderRadius.circular(radius), borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 6,
offset: const Offset(0, 2),
), ),
], child: Column(
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
child: Row(
children: [ children: [
Expanded( ListTile(
dense: true,
contentPadding: EdgeInsets.zero,
title: Text(
d.source_name ?? 'Unnamed location',
style: fontTextStyle(
14,
const Color(0xFF2D2E30),
FontWeight.w600),
),
trailing: IconButton(
icon: Image.asset(
expanded
? 'images/arrow-up.png'
: 'images/downarrow.png',
width: 18,
height: 18,
),
onPressed: () =>
setInner(() => expanded = !expanded),
),
),
if (expanded)
Container(
margin: const EdgeInsets.only(
left: 10, right: 10, bottom: 6),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: const Color(0xFFE5E5E5)),
),
child: Text( child: Text(
title, "Address: ${d.address ?? 'N/A'}",
style: fontTextStyle(12, const Color(0xFF2D2E30), FontWeight.w600), style: fontTextStyle(
12,
const Color(0xFF646566),
FontWeight.w400),
), ),
), ),
if (icon != null) icon!,
], ],
), ),
); );
});
}),
const SizedBox(height: 24),
OutlinedButton.icon(
onPressed: _showAddLocationSheet,
icon: const Icon(Icons.add, size: 18, color: Color(0xFF646566)),
label: Text(
"Add New Location",
style: fontTextStyle(
14, const Color(0xFF646566), FontWeight.w600),
),
),
const SizedBox(height: 12),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF8270DB),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24)),
),
onPressed: () {},
child: Text("Continue",
style: fontTextStyle(
14, Colors.white, FontWeight.w400)),
),
],
),
),
);
} }
} }
// ======= Helper widget =======
class _LabeledField extends StatelessWidget { class _LabeledField extends StatelessWidget {
final String label; final String label;
final Widget child; final Widget child;
final String? Function()? validator; // (kept from your earlier helper; not used here) const _LabeledField({required this.label, required this.child});
const _LabeledField({
required this.label,
required this.child,
this.validator,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final errorText = validator != null ? validator!() : null;
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 14.0), padding: const EdgeInsets.only(bottom: 14),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(label, style: fontTextStyle(12, const Color(0xFF515253), FontWeight.w600)), Text(label,
style: fontTextStyle(
12, const Color(0xFF515253), FontWeight.w600)),
const SizedBox(height: 6), const SizedBox(height: 6),
child, child,
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
),
),
], ],
), ),
); );

@ -2,9 +2,11 @@ import 'dart:convert';
import 'dart:io' show Platform; import 'dart:io' show Platform;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:supplier_new/common/settings.dart'; import 'package:supplier_new/common/settings.dart';
import 'package:supplier_new/resources/source_loctaions_model.dart'; import 'package:supplier_new/resources/source_loctaions_model.dart';
import 'package:supplier_new/resources/sourcelocation_details.dart'; import 'package:supplier_new/resources/sourcelocation_details.dart';
import '../common/keys.dart';
import '../google_maps_place_picker_mb/src/models/pick_result.dart'; import '../google_maps_place_picker_mb/src/models/pick_result.dart';
import '../google_maps_place_picker_mb/src/place_picker.dart'; import '../google_maps_place_picker_mb/src/place_picker.dart';
import 'package:supplier_new/google_maps_place_picker_mb/google_maps_place_picker.dart'; import 'package:supplier_new/google_maps_place_picker_mb/google_maps_place_picker.dart';
@ -42,7 +44,6 @@ class FirstCharUppercaseFormatter extends TextInputFormatter {
} }
} }
void main() => runApp(const MaterialApp(home: ResourcesSourceScreen()));
class ResourcesSourceScreen extends StatefulWidget { class ResourcesSourceScreen extends StatefulWidget {
const ResourcesSourceScreen({super.key}); const ResourcesSourceScreen({super.key});
@ -295,7 +296,6 @@ class _ResourcesSourceScreenState extends State<ResourcesSourceScreen> {
child: OutlinedButton.icon( child: OutlinedButton.icon(
onPressed: () { onPressed: () {
// Your PlacePicker flow goes here (kept commented for reference) // Your PlacePicker flow goes here (kept commented for reference)
/*
location.serviceEnabled().then((value) { location.serviceEnabled().then((value) {
if (value) { if (value) {
initRenderer(); initRenderer();
@ -376,7 +376,6 @@ class _ResourcesSourceScreenState extends State<ResourcesSourceScreen> {
); );
} }
}); });
*/
}, },
icon: Image.asset('images/Add_icon.png', width: 16, height: 16), icon: Image.asset('images/Add_icon.png', width: 16, height: 16),
label: Text( label: Text(

Loading…
Cancel
Save