|
|
|
|
@ -1,9 +1,18 @@
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.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/resources/source_location1.dart';
|
|
|
|
|
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 'Fleet_1.dart';
|
|
|
|
|
void main() => runApp(const MaterialApp(home: SourceLocation()));
|
|
|
|
|
|
|
|
|
|
class SourceLocation extends StatefulWidget {
|
|
|
|
|
@ -17,24 +26,61 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
|
|
|
|
|
// Controllers
|
|
|
|
|
final _nameCtrl = TextEditingController();
|
|
|
|
|
final _locationNameController = TextEditingController();
|
|
|
|
|
final _mobileCtrl = TextEditingController();
|
|
|
|
|
final _altMobileCtrl = 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";
|
|
|
|
|
|
|
|
|
|
var kInitialPosition = const LatLng(15.462477, 78.717401);
|
|
|
|
|
|
|
|
|
|
locationmap.Location location = locationmap.Location();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setState(() {
|
|
|
|
|
_mapsInitialized = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dropdowns
|
|
|
|
|
final List<String> waterTypes = [
|
|
|
|
|
"Drinking Water",
|
|
|
|
|
"Bore Water",
|
|
|
|
|
"Industrial",
|
|
|
|
|
"Construction",
|
|
|
|
|
"Non-potable",
|
|
|
|
|
];
|
|
|
|
|
String? selectedWaterType;
|
|
|
|
|
|
|
|
|
|
String? selectedLicense;
|
|
|
|
|
|
|
|
|
|
final List<String> yearOptions = ["1", "2", "3", "4", "5"];
|
|
|
|
|
String? selectedExperience;
|
|
|
|
|
|
|
|
|
|
// Data bucket
|
|
|
|
|
final List<Map<String, dynamic>> _drivers = [];
|
|
|
|
|
|
|
|
|
|
@ -56,46 +102,71 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_nameCtrl.dispose();
|
|
|
|
|
_locationNameController.dispose();
|
|
|
|
|
_mobileCtrl.dispose();
|
|
|
|
|
_altMobileCtrl.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
bool addBusinessAsSource = false;
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
_nameCtrl.clear();
|
|
|
|
|
_locationNameController.clear();
|
|
|
|
|
_mobileCtrl.clear();
|
|
|
|
|
_altMobileCtrl.clear();
|
|
|
|
|
selectedLicense = null;
|
|
|
|
|
selectedExperience = null;
|
|
|
|
|
selectedWaterType = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _addDriver() {
|
|
|
|
|
void _addSourceLocation() async{
|
|
|
|
|
final ok = _formKey.currentState?.validate() ?? false;
|
|
|
|
|
|
|
|
|
|
if(addBusinessAsSource){
|
|
|
|
|
setState(() {
|
|
|
|
|
address=AppSettings.userAddress;
|
|
|
|
|
lat=AppSettings.supplierLatitude;
|
|
|
|
|
lng=AppSettings.supplierLongitude;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(() {}); // ensure error texts render
|
|
|
|
|
if (!ok ||
|
|
|
|
|
selectedLicense == null ||
|
|
|
|
|
selectedExperience == null ||
|
|
|
|
|
selectedLicense!.isEmpty ||
|
|
|
|
|
selectedExperience!.isEmpty) {
|
|
|
|
|
if (selectedLicense == null || selectedExperience == null) {
|
|
|
|
|
selectedWaterType == null ||
|
|
|
|
|
selectedWaterType!.isEmpty) {
|
|
|
|
|
if (selectedWaterType == null) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
const SnackBar(content: Text("Please select License & Experience")),
|
|
|
|
|
const SnackBar(content: Text("Please select Water type")),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_drivers.add(_buildPayload());
|
|
|
|
|
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})")),
|
|
|
|
|
@ -141,7 +212,7 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
children: [
|
|
|
|
|
// Step indicator
|
|
|
|
|
Text(
|
|
|
|
|
"Step 1/5",
|
|
|
|
|
"Step 3/5",
|
|
|
|
|
style: fontTextStyle(16, const Color(0xFFC3C4C4), FontWeight.w500),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
@ -216,7 +287,7 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
_LabeledField(
|
|
|
|
|
label: "Location Name *",
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _nameCtrl,
|
|
|
|
|
controller: _locationNameController,
|
|
|
|
|
validator: (v) => _required(v, field: "Location Name"),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: "Location Name",
|
|
|
|
|
@ -249,13 +320,106 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Column(
|
|
|
|
|
Visibility(
|
|
|
|
|
visible: !addBusinessAsSource,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
onPressed: _addDriver,
|
|
|
|
|
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",
|
|
|
|
|
@ -266,7 +430,7 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),),
|
|
|
|
|
_LabeledField(
|
|
|
|
|
label: "Water Type *",
|
|
|
|
|
child: DropdownButtonFormField<String>(
|
|
|
|
|
@ -301,7 +465,7 @@ class _SourceLocationState extends State<SourceLocation> {
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
onPressed: _addDriver,
|
|
|
|
|
onPressed: _addSourceLocation,
|
|
|
|
|
icon: Image.asset('images/Add_icon.png', width: 16, height: 16),
|
|
|
|
|
label: Text(
|
|
|
|
|
"Add Location",
|
|
|
|
|
|