|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:supplier_new/common/settings.dart';
|
|
|
|
|
import 'package:supplier_new/resources/source_loctaions_model.dart';
|
|
|
|
|
import '../resources/drivers_model.dart';
|
|
|
|
|
import '../resources/tankers_model.dart';
|
|
|
|
|
|
|
|
|
|
@ -19,8 +20,10 @@ class _AssignDriverScreenState extends State<AssignDriverScreen> {
|
|
|
|
|
double totalFare = 0.0;
|
|
|
|
|
bool isLoading = false;
|
|
|
|
|
bool isTankersDataLoading = false;
|
|
|
|
|
bool isSourceDataLoading = false;
|
|
|
|
|
List<DriversModel> driversList = [];
|
|
|
|
|
List<TankersModel> tankersList = [];
|
|
|
|
|
List<SourceLocationsModel> sourceLocationsList = [];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
@ -28,6 +31,7 @@ class _AssignDriverScreenState extends State<AssignDriverScreen> {
|
|
|
|
|
super.initState();
|
|
|
|
|
_fetchTankers();
|
|
|
|
|
_fetchDrivers();
|
|
|
|
|
_fetchSourceLocations();
|
|
|
|
|
advance = 150;
|
|
|
|
|
advancePayable = advance;
|
|
|
|
|
totalFare = advance + double.parse(widget.order.quoted_amount);
|
|
|
|
|
@ -70,9 +74,28 @@ class _AssignDriverScreenState extends State<AssignDriverScreen> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _fetchSourceLocations() async {
|
|
|
|
|
setState(() => isSourceDataLoading = true);
|
|
|
|
|
try {
|
|
|
|
|
final response = await AppSettings.getSourceLoctaions();
|
|
|
|
|
final data = (jsonDecode(response)['data'] as List)
|
|
|
|
|
.map((e) => SourceLocationsModel.fromJson(e))
|
|
|
|
|
.toList();
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
setState(() {
|
|
|
|
|
sourceLocationsList = data;
|
|
|
|
|
isSourceDataLoading = false;
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("⚠️ Error fetching tankers: $e");
|
|
|
|
|
setState(() => isSourceDataLoading = false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _showAssignTankerBottomSheet() {
|
|
|
|
|
int? selectedTankerIndex;
|
|
|
|
|
int? selectedDriverIndex;
|
|
|
|
|
int? selectedSourceIndex;
|
|
|
|
|
|
|
|
|
|
int _capToLiters(dynamic cap) {
|
|
|
|
|
if (cap == null) return -1;
|
|
|
|
|
@ -432,6 +455,133 @@ class _AssignDriverScreenState extends State<AssignDriverScreen> {
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
|
|
|
|
|
// 🧍 Source Locations List
|
|
|
|
|
Text(
|
|
|
|
|
"SELECT SOURCE LOCATION",
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
10, const Color(0XFF2D2E30), FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
|
|
|
|
|
// 🚨 Driver list disabled until tanker is selected
|
|
|
|
|
selectedTankerIndex == null
|
|
|
|
|
? Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
margin: const EdgeInsets.only(top: 8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0XFFFFFFFF),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: const Color(0xFFC3C4C4)),
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
'Select a tanker to choose source location',
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
14,
|
|
|
|
|
const Color(0xFF2D2E30),
|
|
|
|
|
FontWeight.w400),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: isSourceDataLoading
|
|
|
|
|
? const Center(
|
|
|
|
|
child: CircularProgressIndicator())
|
|
|
|
|
: (driversList.isEmpty
|
|
|
|
|
? Center(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(
|
|
|
|
|
vertical: 12),
|
|
|
|
|
child: Text(
|
|
|
|
|
'No Data Available',
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
12,
|
|
|
|
|
const Color(0xFF939495),
|
|
|
|
|
FontWeight.w500),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.separated(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
physics:
|
|
|
|
|
const NeverScrollableScrollPhysics(),
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
itemCount: sourceLocationsList.length,
|
|
|
|
|
separatorBuilder: (_, __) =>
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
itemBuilder: (context, idx) {
|
|
|
|
|
final d = sourceLocationsList[idx];
|
|
|
|
|
final isSelected =
|
|
|
|
|
selectedSourceIndex == idx;
|
|
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
/* if (isAvailable) {
|
|
|
|
|
setModalState(() {
|
|
|
|
|
selectedDriverIndex = idx;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
AppSettings.longFailedToast(
|
|
|
|
|
'Only available drivers can be selected',
|
|
|
|
|
);
|
|
|
|
|
}*/
|
|
|
|
|
setModalState(() {
|
|
|
|
|
selectedSourceIndex = idx;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Card(
|
|
|
|
|
color:
|
|
|
|
|
const Color(0XFFFFFFFF),
|
|
|
|
|
elevation: 1,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.circular(
|
|
|
|
|
12),
|
|
|
|
|
side: BorderSide(
|
|
|
|
|
color: isSelected
|
|
|
|
|
? primaryColor
|
|
|
|
|
: const Color(
|
|
|
|
|
0XFFC3C4C4),
|
|
|
|
|
width: 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.all(
|
|
|
|
|
12.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Image.asset(
|
|
|
|
|
'images/avatar.png',
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
width: 20,
|
|
|
|
|
height: 20,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
width: 8),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
d.source_name,
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
14,
|
|
|
|
|
const Color(
|
|
|
|
|
0XFF2D2E30),
|
|
|
|
|
FontWeight
|
|
|
|
|
.w500),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|