master
Sneha 1 month ago
parent 3fae53a7d2
commit 252a4c0486

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -0,0 +1 @@
"CFBundleDisplayName" = "Aquick Supplier";

@ -1,6 +1,8 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.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/profile/service_locations_radius.dart';
import '../resources/source_loctaions_model.dart'; import '../resources/source_loctaions_model.dart';
void main() => runApp(const MaterialApp(home: ServiceLocation())); void main() => runApp(const MaterialApp(home: ServiceLocation()));
@ -15,13 +17,14 @@ class ServiceLocation extends StatefulWidget {
class _ServiceLocationState extends State<ServiceLocation> { class _ServiceLocationState extends State<ServiceLocation> {
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
String _deliveryFrom = 'business'; String _deliveryFrom = 'business';
final TextEditingController _radiusController = final TextEditingController _radiusController = TextEditingController(text: "10");
TextEditingController(text: "10");
bool _customizeEachSource = false; bool _customizeEachSource = false;
bool isLoading = false; bool isLoading = false;
int currentStep = 3; int currentStep = 3;
List<SourceLocationsModel> sourceLocationsList = []; List<SourceLocationsModel> sourceLocationsList = [];
// 🔹 Notifier for dynamic map radius
late final ValueNotifier<double> _radiusKmNotifier;
final List<String> _services = [ final List<String> _services = [
"24/7 Emergency services", "24/7 Emergency services",
@ -32,15 +35,31 @@ class _ServiceLocationState extends State<ServiceLocation> {
]; ];
final Set<String> _selectedServices = {}; final Set<String> _selectedServices = {};
final Map<int, bool> _expandedMap = {}; final Map<int, bool> _expandedMap = {};
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_radiusKmNotifier = ValueNotifier<double>(
double.tryParse(_radiusController.text) ?? 10,
);
// 🔹 Listen to radius text changes
_radiusController.addListener(() {
final v = double.tryParse(_radiusController.text);
_radiusKmNotifier.value = (v == null || v.isNaN || v <= 0) ? 10 : v;
});
_fetchSources(); _fetchSources();
} }
@override
void dispose() {
_radiusController.dispose();
_radiusKmNotifier.dispose();
super.dispose();
}
Future<void> _fetchSources() async { Future<void> _fetchSources() async {
setState(() => isLoading = true); setState(() => isLoading = true);
try { try {
@ -76,290 +95,336 @@ class _ServiceLocationState extends State<ServiceLocation> {
child: isLoading child: isLoading
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
: Form( : Form(
key: _formKey, key: _formKey,
child: ListView( child: ListView(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 24), padding: const EdgeInsets.fromLTRB(20, 10, 20, 24),
children: [ children: [
Text("Step $currentStep/5", Text("Step $currentStep/5",
style: fontTextStyle(16, Color(0xFFC3C4C4), FontWeight.w500)), style: fontTextStyle(
const SizedBox(height: 16), 16, const Color(0xFFC3C4C4), FontWeight.w500)),
Row( const SizedBox(height: 16),
children: List.generate(5, (index) { Row(
final isFilled = index < currentStep; children: List.generate(5, (index) {
return Expanded( final isFilled = index < currentStep;
child: Container( return Expanded(
margin: const EdgeInsets.symmetric(horizontal: 2), child: Container(
height: 5, margin: const EdgeInsets.symmetric(horizontal: 2),
decoration: BoxDecoration( height: 5,
color: isFilled decoration: BoxDecoration(
? const Color(0xFF0D3771) color: isFilled
: const Color(0xFFE6E6E6), ? const Color(0xFF0D3771)
borderRadius: BorderRadius.circular(2), : const Color(0xFFE6E6E6),
), borderRadius: BorderRadius.circular(2),
), ),
);
}),
), ),
);
}),
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text("SERVICE LOCATIONS",
style: fontTextStyle(
20, const Color(0xFF515253), FontWeight.w600)),
const SizedBox(height: 16),
Align(
alignment: Alignment.centerLeft,
child: Image.asset('images/marker-pin.png',
width: 24, height: 24),
),
const SizedBox(height: 16),
Text(
"Define where you want to provide delivery services",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w500),
),
const SizedBox(height: 16),
Text("SERVICE LOCATIONS", RadioListTile<String>(
style: fontTextStyle(20, Color(0xFF515253), FontWeight.w600)), value: 'business',
groupValue: _deliveryFrom,
onChanged: (value) =>
setState(() => _deliveryFrom = value ?? 'business'),
title: Text("From Business Location",
style: fontTextStyle(
12, const Color(0xFF2D2E30), FontWeight.w400)),
dense: true,
contentPadding: EdgeInsets.zero,
visualDensity:
const VisualDensity(horizontal: 0, vertical: -3),
),
RadioListTile<String>(
value: 'source',
groupValue: _deliveryFrom,
onChanged: (value) =>
setState(() => _deliveryFrom = value ?? 'source'),
title: Text("From Source Locations",
style: fontTextStyle(
12, const Color(0xFF2D2E30), FontWeight.w400)),
dense: true,
contentPadding: EdgeInsets.zero,
visualDensity:
const VisualDensity(horizontal: 0, vertical: -3),
),
const SizedBox(height: 16),
// 🔹 BUSINESS LOCATION SECTION
Visibility(
visible: _deliveryFrom == 'business',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Delivery Radius (in Kms) *",
style: fontTextStyle(
12, const Color(0xFF2F3036), FontWeight.w600)),
const SizedBox(height: 16), const SizedBox(height: 16),
Align( TextFormField(
alignment: Alignment.centerLeft, controller: _radiusController,
child: Image.asset('images/marker-pin.png', keyboardType: TextInputType.number,
width: 24, height: 24), decoration: InputDecoration(
hintText: "Enter radius in kms",
hintStyle: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w400),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 12),
),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Container(
"Define where you want to provide delivery services", width: double.infinity,
style: fontTextStyle(14, Color(0xFF939495), FontWeight.w500), height: 220, // 👈 small map fits neatly
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFFE6E6E6)),
borderRadius: BorderRadius.circular(8),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: ServiceLocationsRadiusScreen(
initialPosition: const LatLng(17.381597, 78.481791),
radiusKmListenable: _radiusKmNotifier,
),
),
), ),
const SizedBox(height: 16), ],
),
),
RadioListTile<String>( // 🔹 SOURCE LOCATIONS SECTION
value: 'business', Visibility(
groupValue: _deliveryFrom, visible: _deliveryFrom == 'source',
onChanged: (value) => child: Column(
setState(() => _deliveryFrom = value ?? 'business'), crossAxisAlignment: CrossAxisAlignment.start,
title: Text("From Business Location", children: [
style: fontTextStyle(12, Color(0xFF2D2E30), FontWeight.w400)), Text("Delivery Radius (in Kms) *",
dense: true, style: fontTextStyle(
contentPadding: EdgeInsets.zero, 12, const Color(0xFF2F3036), FontWeight.w600)),
visualDensity: const SizedBox(height: 16),
const VisualDensity(horizontal: 0, vertical: -3), TextFormField(
), controller: _radiusController,
RadioListTile<String>( keyboardType: TextInputType.number,
value: 'source', decoration: InputDecoration(
groupValue: _deliveryFrom, hintText: "Enter radius in kms",
onChanged: (value) => hintStyle: fontTextStyle(
setState(() => _deliveryFrom = value ?? 'source'), 14, const Color(0xFF939495), FontWeight.w400),
title: Text("From Source Locations", border: OutlineInputBorder(
style: fontTextStyle(12, Color(0xFF2D2E30), FontWeight.w400)), borderRadius: BorderRadius.circular(8),
dense: true, ),
contentPadding: EdgeInsets.zero, contentPadding: const EdgeInsets.symmetric(
visualDensity: horizontal: 12, vertical: 12),
const VisualDensity(horizontal: 0, vertical: -3), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Row(
children: [
Visibility( Checkbox(
visible: _deliveryFrom == 'business', value: _customizeEachSource,
child: Column( onChanged: (val) => setState(
crossAxisAlignment: CrossAxisAlignment.start, () => _customizeEachSource = val ?? false),
children: [ materialTapTargetSize:
Text("Delivery Radius (in Kms) *", MaterialTapTargetSize.shrinkWrap,
style: fontTextStyle(12, Color(0xFF2F3036), FontWeight.w600)), visualDensity: const VisualDensity(
const SizedBox(height: 16), horizontal: -4, vertical: -4),
TextFormField( ),
controller: _radiusController, const SizedBox(width: 6),
keyboardType: TextInputType.number, Expanded(
decoration: InputDecoration( child: Text(
hintText: "Enter radius in kms", "Customize for each source location",
hintStyle: fontTextStyle(14, Color(0xFF939495), FontWeight.w400), style: fontTextStyle(
border: OutlineInputBorder( 12, const Color(0xFF2D2E30),
borderRadius: BorderRadius.circular(8), FontWeight.w400),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 12),
),
),
const SizedBox(height: 16),
Container(
width: double.infinity,
height: 160,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('images/google_maps.png'),
fit: BoxFit.contain,
),
),
), ),
], ),
), ],
), ),
const SizedBox(height: 12),
// Source Location Customization Section // 🔹 Show source list if enabled
Visibility( if (_customizeEachSource)
visible: _deliveryFrom == 'source', Column(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: sourceLocationsList.isEmpty
Text("Delivery Radius (in Kms) *", ? [
style: fontTextStyle(12, Color(0xFF2F3036), FontWeight.w600)), const Text(
const SizedBox(height: 16), "No source locations available"),
TextFormField( ]
controller: _radiusController, : List.generate(sourceLocationsList.length,
keyboardType: TextInputType.number, (index) {
decoration: InputDecoration( final d = sourceLocationsList[index];
hintText: "Enter radius in kms", final isExpanded =
hintStyle: fontTextStyle(14, const Color(0xFF939495), FontWeight.w400), _expandedMap[index] ?? false;
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 12),
),
),
const SizedBox(height: 16),
Row(
children: [
Checkbox(
value: _customizeEachSource,
onChanged: (val) => setState(
() => _customizeEachSource = val ?? false),
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
visualDensity: const VisualDensity(
horizontal: -4, vertical: -4),
),
const SizedBox(width: 6),
Expanded( return Container(
child: Text( margin:
"Customize for each source location", const EdgeInsets.only(bottom: 8),
style: fontTextStyle(12, Color(0xFF2D2E30), FontWeight.w400), decoration: BoxDecoration(
color: const Color(0xFFF7F7F7),
border: Border.all(
color:
const Color(0xFFE5E5E5)),
borderRadius:
BorderRadius.circular(12),
), ),
), child: Column(
], children: [
), ListTile(
const SizedBox(height: 12), dense: true,
contentPadding:
// 🔹 Show all source locations when checkbox checked EdgeInsets.zero,
if (_customizeEachSource) minVerticalPadding: 0,
Column( visualDensity:
crossAxisAlignment: CrossAxisAlignment.start, const VisualDensity(
children: sourceLocationsList.isEmpty vertical: -4,
? [ horizontal: 0),
const Text("No source locations available"), title: Text(
] d.source_name ??
: List.generate(sourceLocationsList.length, (index) { 'Unnamed location',
final d = sourceLocationsList[index]; style: fontTextStyle(
return StatefulBuilder( 14,
builder: (context, setInner) { const Color(0xFF2D2E30),
// Always read from map dynamically (not fixed final variable) FontWeight.w600),
final isExpanded = _expandedMap[index] ?? false;
return Container(
margin: const EdgeInsets.only(bottom: 8),
decoration: BoxDecoration(
color: const Color(0xFFF7F7F7),
border: Border.all(color: const Color(0xFFE5E5E5)),
borderRadius: BorderRadius.circular(12),
), ),
child: Column( trailing: IconButton(
children: [ icon: Image.asset(
ListTile( isExpanded
dense: true, ? 'images/arrow-up.png'
contentPadding: EdgeInsets.zero, : 'images/downarrow.png',
minVerticalPadding: 0, width: 18,
visualDensity: const VisualDensity(vertical: -4, horizontal: 0), height: 18,
title: Text( ),
d.source_name ?? 'Unnamed location', onPressed: () {
style: fontTextStyle(14, const Color(0xFF2D2E30), FontWeight.w600), setState(() {
), _expandedMap[index] =
trailing: IconButton( !isExpanded;
icon: Image.asset( });
isExpanded },
? 'images/arrow-up.png'
: 'images/downarrow.png',
width: 18,
height: 18,
),
onPressed: () {
setInner(() {
_expandedMap[index] = !isExpanded;
});
},
),
),
if (isExpanded)
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),
),
),
],
), ),
); ),
}, if (isExpanded)
); Container(
}), margin:
), const EdgeInsets.only(
left: 10,
const SizedBox(height: 16), right: 10,
Container( bottom: 6),
width: double.infinity, padding:
height: 160, const EdgeInsets.all(10),
decoration: const BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( color: Colors.white,
image: AssetImage('images/google_maps.png'), borderRadius:
fit: BoxFit.contain, 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),
Text("Types of Services",
style: fontTextStyle(16, Color(0xFF2D2E30), FontWeight.w600)),
const SizedBox(height: 12),
Text(
"Define what type of services you would wish to provide",
style: fontTextStyle(14, Color(0xFF939495), FontWeight.w500)),
const SizedBox(height: 16), const SizedBox(height: 16),
..._services Container(
.map((service) => _serviceItem(service))
.toList(),
const SizedBox(height: 24),
SizedBox(
width: double.infinity, width: double.infinity,
child: ElevatedButton( height: 250,
style: ElevatedButton.styleFrom( decoration: BoxDecoration(
backgroundColor: const Color(0xFF8270DB), border:
foregroundColor: Colors.white, Border.all(color: const Color(0xFFE6E6E6)),
padding: const EdgeInsets.symmetric(vertical: 14), borderRadius: BorderRadius.circular(8),
shape: RoundedRectangleBorder( ),
borderRadius: BorderRadius.circular(24)), child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: ServiceLocationsRadiusScreen(
initialPosition:
const LatLng(20.5937, 78.9629),
radiusKmListenable: _radiusKmNotifier,
), ),
onPressed: () {
final selected = _selectedServices.isEmpty
? "No services selected"
: _selectedServices.join(", ");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Saved successfully for ${_deliveryFrom == 'business' ? 'Business Location' : 'Source Locations'}\nSelected: $selected"),
),
);
},
child: Text("Save & Continue",
style: fontTextStyle(14, Color(0xFFFFFFFF), FontWeight.w400)),
), ),
), ),
], ],
), ),
), ),
const SizedBox(height: 24),
Text("Types of Services",
style: fontTextStyle(
16, const Color(0xFF2D2E30), FontWeight.w600)),
const SizedBox(height: 12),
Text("Define what type of services you would wish to provide",
style: fontTextStyle(
14, const Color(0xFF939495), FontWeight.w500)),
const SizedBox(height: 16),
..._services.map((service) => _serviceItem(service)).toList(),
const SizedBox(height: 24),
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: () {
final selected = _selectedServices.isEmpty
? "No services selected"
: _selectedServices.join(", ");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Saved successfully for ${_deliveryFrom == 'business' ? 'Business Location' : 'Source Locations'}\nSelected: $selected"),
),
);
},
child: Text("Save & Continue",
style: fontTextStyle(
14, Colors.white, FontWeight.w400)),
),
),
],
),
),
), ),
); );
} }
// Service item // Service item checkbox list
Widget _serviceItem(String label) { Widget _serviceItem(String label) {
final bool selected = _selectedServices.contains(label); final bool selected = _selectedServices.contains(label);
return GestureDetector( return GestureDetector(
@ -378,13 +443,14 @@ class _ServiceLocationState extends State<ServiceLocation> {
children: [ children: [
Icon( Icon(
selected ? Icons.check_box : Icons.check_box_outline_blank, selected ? Icons.check_box : Icons.check_box_outline_blank,
color: selected ? Color(0xFF8270DB) : Color(0xFF939495), color: selected ? const Color(0xFF8270DB) : const Color(0xFF939495),
size: 20, size: 20,
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: Text(label, style: fontTextStyle(12, Color(0xFF2D2E30), FontWeight.w400), child: Text(label,
), style: fontTextStyle(
12, const Color(0xFF2D2E30), FontWeight.w400)),
), ),
], ],
), ),

@ -0,0 +1,147 @@
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:permission_handler/permission_handler.dart';
class ServiceLocationsRadiusScreen extends StatefulWidget {
final LatLng? initialPosition;
final ValueListenable<double>? radiusKmListenable;
const ServiceLocationsRadiusScreen({
Key? key,
this.initialPosition,
this.radiusKmListenable,
}) : super(key: key);
@override
State<ServiceLocationsRadiusScreen> createState() =>
_ServiceLocationsRadiusScreenState();
}
class _ServiceLocationsRadiusScreenState
extends State<ServiceLocationsRadiusScreen> {
GoogleMapController? _controller;
LatLng? _currentPosition;
LatLng? _circleCenter;
bool _isMapReady = false;
Set<Circle> _circles = {};
final double _fallbackRadiusMeters = 10000; // 10 km
final LatLng _indiaCenter = const LatLng(20.5937, 78.9629);
@override
void initState() {
super.initState();
if (widget.initialPosition == null) {
_checkLocationPermissionAndGetCurrentPosition();
} else {
_circleCenter = widget.initialPosition;
}
widget.radiusKmListenable?.addListener(_onRadiusChangedFromParent);
}
@override
void dispose() {
widget.radiusKmListenable?.removeListener(_onRadiusChangedFromParent);
super.dispose();
}
// 🔹 When radius changes in parent
void _onRadiusChangedFromParent() {
final km =
widget.radiusKmListenable?.value ?? (_fallbackRadiusMeters / 1000.0);
final meters = km * 1000.0;
final center = _circleCenter ?? _currentPosition ?? _indiaCenter;
_addRadiusCircle(center, radiusInMeters: meters);
}
// 🔹 Get current location
Future<void> _checkLocationPermissionAndGetCurrentPosition() async {
var status = await Permission.location.status;
if (!status.isGranted) {
status = await Permission.location.request();
if (!status.isGranted) return;
}
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) return;
final position = await Geolocator.getCurrentPosition();
setState(() {
_currentPosition = LatLng(position.latitude, position.longitude);
});
}
// 🔹 Add / update the circle
void _addRadiusCircle(LatLng center, {double? radiusInMeters}) async {
final meters = radiusInMeters ??
(widget.radiusKmListenable?.value ?? (_fallbackRadiusMeters / 1000.0)) *
1000.0;
setState(() {
_circleCenter = center;
_circles = {
Circle(
circleId: const CircleId("radius_circle"),
center: center,
radius: meters,
fillColor: Colors.blue.withOpacity(0.2),
strokeColor: Colors.blueAccent,
strokeWidth: 2,
),
};
});
// 👇 adjust zoom so full circle is visible even in small container
if (_controller != null) {
final zoom = _getZoomLevelForSmallMap(meters);
await _controller!.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(target: center, zoom: zoom),
),
);
}
}
// 🔹 Calculate zoom for small map container (200300 px)
double _getZoomLevelForSmallMap(double radiusMeters) {
// Adjust constant here if map size differs
final scale = radiusMeters / 200; // Smaller scale for small map
double zoomLevel = 16 - log(scale) / log(2);
if (zoomLevel > 18) zoomLevel = 18;
if (zoomLevel < 4) zoomLevel = 4;
return zoomLevel;
}
@override
Widget build(BuildContext context) {
final LatLng target =
widget.initialPosition ?? _currentPosition ?? _indiaCenter;
final initialCameraPosition = CameraPosition(
target: target,
zoom: 12,
);
return GoogleMap(
initialCameraPosition: initialCameraPosition,
mapType: MapType.normal,
circles: _circles,
zoomControlsEnabled: false,
myLocationEnabled: false,
myLocationButtonEnabled: false,
onMapCreated: (controller) async {
_controller = controller;
_isMapReady = true;
await Future.delayed(const Duration(milliseconds: 500));
final center = widget.initialPosition ?? _currentPosition ?? _indiaCenter;
final km = widget.radiusKmListenable?.value ?? 10;
_addRadiusCircle(center, radiusInMeters: km * 1000.0);
},
);
}
}
Loading…
Cancel
Save