|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.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/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_platform_interface/google_maps_flutter_platform_interface.dart';
|
|
|
|
|
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 {
|
|
|
|
|
const SourceLocation({super.key});
|
|
|
|
|
@ -22,56 +22,44 @@ class SourceLocation extends StatefulWidget {
|
|
|
|
|
State<SourceLocation> createState() => _SourceLocationState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
PickResult? selectedPlace;
|
|
|
|
|
bool _mapsInitialized = false;
|
|
|
|
|
final String _mapsRenderer = "latest";
|
|
|
|
|
|
|
|
|
|
bool _mapsInitialized = false;
|
|
|
|
|
final String _mapsRenderer = "latest";
|
|
|
|
|
|
|
|
|
|
var kInitialPosition = const LatLng(15.462477, 78.717401);
|
|
|
|
|
var kInitialPosition = const LatLng(15.462477, 78.717401);
|
|
|
|
|
|
|
|
|
|
locationmap.Location location = locationmap.Location();
|
|
|
|
|
locationmap.Location location = locationmap.Location();
|
|
|
|
|
|
|
|
|
|
final GoogleMapsFlutterPlatform mapsImplementation =
|
|
|
|
|
GoogleMapsFlutterPlatform.instance;
|
|
|
|
|
final GoogleMapsFlutterPlatform mapsImplementation =
|
|
|
|
|
GoogleMapsFlutterPlatform.instance;
|
|
|
|
|
|
|
|
|
|
void initRenderer() {
|
|
|
|
|
if (_mapsInitialized) return;
|
|
|
|
|
if (mapsImplementation is GoogleMapsFlutterAndroid) {
|
|
|
|
|
switch (_mapsRenderer) {
|
|
|
|
|
case "legacy":
|
|
|
|
|
(mapsImplementation as GoogleMapsFlutterAndroid)
|
|
|
|
|
.initializeWithRenderer(AndroidMapRenderer.legacy);
|
|
|
|
|
break;
|
|
|
|
|
case "latest":
|
|
|
|
|
(mapsImplementation as GoogleMapsFlutterAndroid)
|
|
|
|
|
.initializeWithRenderer(AndroidMapRenderer.latest);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
void initRenderer() {
|
|
|
|
|
if (_mapsInitialized) return;
|
|
|
|
|
if (mapsImplementation is GoogleMapsFlutterAndroid) {
|
|
|
|
|
switch (_mapsRenderer) {
|
|
|
|
|
case "legacy":
|
|
|
|
|
(mapsImplementation as GoogleMapsFlutterAndroid)
|
|
|
|
|
.initializeWithRenderer(AndroidMapRenderer.legacy);
|
|
|
|
|
break;
|
|
|
|
|
case "latest":
|
|
|
|
|
(mapsImplementation as GoogleMapsFlutterAndroid)
|
|
|
|
|
.initializeWithRenderer(AndroidMapRenderer.latest);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setState(() {
|
|
|
|
|
_mapsInitialized = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// setState(() {
|
|
|
|
|
// _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 = [
|
|
|
|
|
"Drinking Water",
|
|
|
|
|
"Bore Water",
|
|
|
|
|
@ -79,514 +67,390 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
"Construction",
|
|
|
|
|
"Non-potable",
|
|
|
|
|
];
|
|
|
|
|
String? selectedWaterType;
|
|
|
|
|
|
|
|
|
|
// Data bucket
|
|
|
|
|
final List<Map<String, dynamic>> _drivers = [];
|
|
|
|
|
|
|
|
|
|
// Validators
|
|
|
|
|
String? _required(String? v, {String field = "This field"}) {
|
|
|
|
|
if (v == null || v.trim().isEmpty) return "$field is required";
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// For map
|
|
|
|
|
bool _mapsInitialized = false;
|
|
|
|
|
final GoogleMapsFlutterPlatform mapsImplementation =
|
|
|
|
|
GoogleMapsFlutterPlatform.instance;
|
|
|
|
|
final locationmap.Location location = locationmap.Location();
|
|
|
|
|
var kInitialPosition = const LatLng(15.462477, 78.717401);
|
|
|
|
|
|
|
|
|
|
String? _validatePhone(String? v, {String label = "Phone Number"}) {
|
|
|
|
|
if (v == null || v.trim().isEmpty) return "$label is required";
|
|
|
|
|
final digits = v.replaceAll(RegExp(r'\D'), '');
|
|
|
|
|
if (digits.length != 10) return "Enter a 10-digit $label";
|
|
|
|
|
if (!RegExp(r'^[6-9]\d{9}$').hasMatch(digits)) {
|
|
|
|
|
return "$label must start with 6/7/8/9";
|
|
|
|
|
void initRenderer() {
|
|
|
|
|
if (_mapsInitialized) return;
|
|
|
|
|
if (mapsImplementation is GoogleMapsFlutterAndroid) {
|
|
|
|
|
(mapsImplementation as GoogleMapsFlutterAndroid)
|
|
|
|
|
.initializeWithRenderer(AndroidMapRenderer.latest);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
setState(() => _mapsInitialized = true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_locationNameController.dispose();
|
|
|
|
|
_mobileCtrl.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
bool addBusinessAsSource = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _clearForm() {
|
|
|
|
|
_locationNameController.clear();
|
|
|
|
|
_mobileCtrl.clear();
|
|
|
|
|
selectedWaterType = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_fetchSources();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _addSourceLocation() async{
|
|
|
|
|
final ok = _formKey.currentState?.validate() ?? false;
|
|
|
|
|
|
|
|
|
|
if(addBusinessAsSource){
|
|
|
|
|
Future<void> _fetchSources() async {
|
|
|
|
|
setState(() => isLoading = true);
|
|
|
|
|
try {
|
|
|
|
|
final response = await AppSettings.getSourceLoctaions();
|
|
|
|
|
final data = (jsonDecode(response)['data'] as List)
|
|
|
|
|
.map((e) => SourceLocationsModel.fromJson(e))
|
|
|
|
|
.toList();
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
setState(() {
|
|
|
|
|
address=AppSettings.userAddress;
|
|
|
|
|
lat=AppSettings.supplierLatitude;
|
|
|
|
|
lng=AppSettings.supplierLongitude;
|
|
|
|
|
sourceLocationsList = data;
|
|
|
|
|
isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
} 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>();
|
|
|
|
|
payload["location_name"] = _locationNameController.text.toString();
|
|
|
|
|
payload["phone"] = _mobileCtrl.text.toString();
|
|
|
|
|
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();
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(content: Text("Driver added (${_drivers.length})")),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
String? _required(String? v, {String field = "This field"}) {
|
|
|
|
|
if (v == null || v.trim().isEmpty) return "$field is required";
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String? _validatePhone(String? v, {String label = "Phone"}) {
|
|
|
|
|
if (v == null || v.trim().isEmpty) return "$label is required";
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
context: context,
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
surfaceTintColor: Colors.transparent,
|
|
|
|
|
elevation: 0,
|
|
|
|
|
scrolledUnderElevation: 0,
|
|
|
|
|
title: const Text("Complete Profile"),
|
|
|
|
|
actions: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(10, 10, 0, 10),
|
|
|
|
|
child: IconButton(
|
|
|
|
|
splashRadius: 20,
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
icon: const Image(image: AssetImage('images/calendar_appbar.png'), width: 22, height: 22),
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
),
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
left: 20,
|
|
|
|
|
right: 20,
|
|
|
|
|
top: 20,
|
|
|
|
|
bottom: MediaQuery.of(context).viewInsets.bottom + 20,
|
|
|
|
|
),
|
|
|
|
|
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: Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: ListView(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 10, 20, 24),
|
|
|
|
|
children: [
|
|
|
|
|
// Step indicator
|
|
|
|
|
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: SingleChildScrollView(
|
|
|
|
|
child: Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 2),
|
|
|
|
|
height: 5,
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 4,
|
|
|
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: index < 4 ? const Color(0xFFC3C4C4) : Colors.grey,
|
|
|
|
|
color: Colors.grey[300],
|
|
|
|
|
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),
|
|
|
|
|
Align(
|
|
|
|
|
alignment: Alignment.centerLeft, // keep the whole thing on the left
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min, // don't stretch full width
|
|
|
|
|
children: [
|
|
|
|
|
Checkbox(
|
|
|
|
|
value: addBusinessAsSource,
|
|
|
|
|
onChanged: (v) => setState(() => addBusinessAsSource = v ?? false),
|
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
|
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
|
|
|
|
|
Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
"Add Source Location",
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
16, const Color(0xFF2D2E30), FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
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),
|
|
|
|
|
_LabeledField(
|
|
|
|
|
label: "Location Name *",
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _locationNameController,
|
|
|
|
|
validator: (v) => _required(v, field: "Location Name"),
|
|
|
|
|
textCapitalization: TextCapitalization.none,
|
|
|
|
|
inputFormatters: const [
|
|
|
|
|
FirstCharUppercaseFormatter(), // << live first-letter caps
|
|
|
|
|
],
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: "Location Name",
|
|
|
|
|
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
isDense: true,
|
|
|
|
|
),
|
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
label: "Location Name *",
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _locationNameController,
|
|
|
|
|
validator: (v) => _required(v, field: "Location Name"),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: "Location Name",
|
|
|
|
|
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
isDense: true,
|
|
|
|
|
),
|
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_LabeledField(
|
|
|
|
|
label: "Mobile Number *",
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _mobileCtrl,
|
|
|
|
|
validator: (v) => _validatePhone(v, label: "Mobile Number"),
|
|
|
|
|
keyboardType: TextInputType.phone,
|
|
|
|
|
inputFormatters: [
|
|
|
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
|
|
|
LengthLimitingTextInputFormatter(10),
|
|
|
|
|
],
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: "Mobile Number",
|
|
|
|
|
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
isDense: true,
|
|
|
|
|
),
|
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Visibility(
|
|
|
|
|
visible: !addBusinessAsSource,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
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: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
child: const Text("Cancel"),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
icon: Image.asset('images/Add_icon.png', width: 16, height: 16),
|
|
|
|
|
label: Text(
|
|
|
|
|
"Add Location on map",
|
|
|
|
|
style: fontTextStyle(14, const Color(0xFF646566), FontWeight.w600),
|
|
|
|
|
_LabeledField(
|
|
|
|
|
label: "Mobile Number *",
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _mobileCtrl,
|
|
|
|
|
validator: (v) => _validatePhone(v, label: "Mobile Number"),
|
|
|
|
|
keyboardType: TextInputType.phone,
|
|
|
|
|
inputFormatters: [
|
|
|
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
|
|
|
LengthLimitingTextInputFormatter(10),
|
|
|
|
|
],
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: "Mobile Number",
|
|
|
|
|
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
isDense: true,
|
|
|
|
|
),
|
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
),),
|
|
|
|
|
_LabeledField(
|
|
|
|
|
label: "Water Type *",
|
|
|
|
|
child: DropdownButtonFormField<String>(
|
|
|
|
|
value: selectedWaterType,
|
|
|
|
|
items: waterTypes
|
|
|
|
|
.map((w) => DropdownMenuItem(value: w, child: Text(w)))
|
|
|
|
|
.toList(),
|
|
|
|
|
onChanged: (v) => setState(() => selectedWaterType = v),
|
|
|
|
|
validator: (v) => v == null || v.isEmpty ? "Water Type is required" : null,
|
|
|
|
|
isExpanded: true,
|
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
|
hint: Text(
|
|
|
|
|
"Select Water 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),
|
|
|
|
|
Visibility(
|
|
|
|
|
visible: !addBusinessAsSource,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
},
|
|
|
|
|
icon: Image.asset('images/Add_icon.png', width: 16, height: 16),
|
|
|
|
|
label: Text(
|
|
|
|
|
"Add Location on map",
|
|
|
|
|
style: fontTextStyle(14, const Color(0xFF646566), FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
_LabeledField(
|
|
|
|
|
label: "Water Type *",
|
|
|
|
|
child: DropdownButtonFormField<String>(
|
|
|
|
|
value: selectedWaterType,
|
|
|
|
|
items: waterTypes
|
|
|
|
|
.map((w) => DropdownMenuItem(value: w, child: Text(w)))
|
|
|
|
|
.toList(),
|
|
|
|
|
onChanged: (v) => setState(() => selectedWaterType = v),
|
|
|
|
|
validator: (v) => v == null || v.isEmpty ? "Water Type is required" : null,
|
|
|
|
|
isExpanded: true,
|
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
|
hint: Text(
|
|
|
|
|
"Select Water 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),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
backgroundColor: const Color(0xFF8270DB),
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(24)),
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// // TODO: Navigate to the next step/screen
|
|
|
|
|
// Navigator.push(context, MaterialPageRoute(builder: (_) => const SourceLocation1()));
|
|
|
|
|
// // ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
// // SnackBar(content: Text("Saved ${_drivers.length} driver(s). Proceeding…")),
|
|
|
|
|
// // );
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
if (_formKey.currentState?.validate() ?? false) {
|
|
|
|
|
var payload = {
|
|
|
|
|
"location_name": _nameCtrl.text,
|
|
|
|
|
"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: Text(
|
|
|
|
|
"Continue",
|
|
|
|
|
style: fontTextStyle(14, Colors.white, FontWeight.w400),
|
|
|
|
|
),
|
|
|
|
|
child: const Text("Save Location",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 14, color: Colors.white)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ======= 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),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
surfaceTintColor: Colors.transparent,
|
|
|
|
|
elevation: 0,
|
|
|
|
|
title: const Text("Complete Profile"),
|
|
|
|
|
),
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
title,
|
|
|
|
|
style: fontTextStyle(12, const Color(0xFF2D2E30), FontWeight.w600),
|
|
|
|
|
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(
|
|
|
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 12, vertical: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFFF1F1F1),
|
|
|
|
|
border: Border.all(color: const Color(0xFFE5E5E5)),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
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(
|
|
|
|
|
"Address: ${d.address ?? 'N/A'}",
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
12,
|
|
|
|
|
const Color(0xFF646566),
|
|
|
|
|
FontWeight.w400),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (icon != null) icon!,
|
|
|
|
|
],
|
|
|
|
|
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 {
|
|
|
|
|
final String label;
|
|
|
|
|
final Widget child;
|
|
|
|
|
final String? Function()? validator; // (kept from your earlier helper; not used here)
|
|
|
|
|
|
|
|
|
|
const _LabeledField({
|
|
|
|
|
required this.label,
|
|
|
|
|
required this.child,
|
|
|
|
|
this.validator,
|
|
|
|
|
});
|
|
|
|
|
const _LabeledField({required this.label, required this.child});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final errorText = validator != null ? validator!() : null;
|
|
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 14.0),
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 14),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
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),
|
|
|
|
|
child,
|
|
|
|
|
if (errorText != null)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 6),
|
|
|
|
|
child: Text(
|
|
|
|
|
errorText,
|
|
|
|
|
style: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|