showSimplePickerLocation function
Future<GeoPoint?>
showSimplePickerLocation({
- required BuildContext context,
- Widget? titleWidget,
- PickerMarkerBuilder? pickMarkerWidget,
- String? title,
- TextStyle? titleStyle,
- String? textConfirmPicker,
- String? textCancelPicker,
- EdgeInsets contentPadding = EdgeInsets.zero,
- double radius = 0.0,
- GeoPoint? initPosition,
- ZoomOption zoomOption = const ZoomOption(),
- bool isDismissible = false,
- UserTrackingOption? initCurrentUserPosition,
showSimplePickerLocation : picker to select specific position
context
: (BuildContext) dialog context parent
titleWidget
: (Widget) widget title of the dialog
title
: (String) text title widget of the dialog
titleStyle
: (TextStyle) style text title widget of the dialog
textConfirmPicker
: (String) text confirm button widget of the dialog
textCancelPicker
: (String) text cancel button widget of the dialog
radius
: (double) rounded radius of the dialog
isDismissible
: (bool) to indicate if tapping out side of dialog will dismiss the dialog
initCurrentUserPosition
: (GeoPoint) to indicate initialize position in the map
initPosition
: (bool) to initialize the map in user location
Implementation
Future<GeoPoint?> showSimplePickerLocation({
required BuildContext context,
Widget? titleWidget,
PickerMarkerBuilder? pickMarkerWidget,
String? title,
TextStyle? titleStyle,
String? textConfirmPicker,
String? textCancelPicker,
EdgeInsets contentPadding = EdgeInsets.zero,
double radius = 0.0,
GeoPoint? initPosition,
ZoomOption zoomOption = const ZoomOption(),
bool isDismissible = false,
UserTrackingOption? initCurrentUserPosition,
}) async {
assert(title == null || titleWidget == null);
assert(((initCurrentUserPosition != null) && initPosition == null) ||
((initCurrentUserPosition == null) && initPosition != null));
final MapController controller = MapController(
initMapWithUserPosition: initCurrentUserPosition,
initPosition: initPosition,
);
GeoPoint? center;
GeoPoint? old;
GeoPoint? point = await showDialog(
context: context,
builder: (ctx) {
return PopScope(
canPop: isDismissible,
child: SizedBox(
height: MediaQuery.of(context).size.height / 2.4,
width: MediaQuery.of(context).size.height / 2,
child: AlertDialog(
title: title != null
? Text(
title,
style: titleStyle,
)
: titleWidget,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(radius),
),
),
contentPadding: contentPadding,
content: SizedBox(
height: MediaQuery.of(context).size.height / 2.5,
width: MediaQuery.of(context).size.height / 2,
child: StatefulBuilder(
builder: (context, setState) {
return Stack(
children: [
Positioned.fill(
child: OSMFlutter(
controller: controller,
onMapMoved: (regsion) {
setState(
() {
old = center;
center = regsion.center;
},
);
},
osmOption: OSMOption(
zoomOption: zoomOption,
isPicker: true,
),
),
),
Positioned(
child: pickMarkerWidget != null
? pickMarkerWidget(
context,
center != null && old != null
? center!.isEqual(old!)
: center != null && old == null
? true
: false)
: AnimatedCenterMarker(
center: center,
),
)
],
);
},
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: Text(
textCancelPicker ??
MaterialLocalizations.of(context).cancelButtonLabel,
),
),
ElevatedButton(
onPressed: () async {
final center = await controller.centerMap;
if (!ctx.mounted) return;
Navigator.pop(ctx, center);
},
child: Text(
textConfirmPicker ??
MaterialLocalizations.of(context).okButtonLabel,
),
),
],
),
),
);
},
);
return point;
}