showSimplePickerLocation function

Future<GeoPoint?> showSimplePickerLocation({
  1. required BuildContext context,
  2. Widget? titleWidget,
  3. String? title,
  4. TextStyle? titleStyle,
  5. String? textConfirmPicker,
  6. String? textCancelPicker,
  7. EdgeInsets contentPadding = EdgeInsets.zero,
  8. double radius = 0.0,
  9. GeoPoint? initPosition,
  10. ZoomOption zoomOption = const ZoomOption(),
  11. bool isDismissible = false,
  12. 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,
  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? 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: OSMFlutter(
                controller: controller,
                osmOption: OSMOption(
                  zoomOption: zoomOption,
                  isPicker: true,
                ),
              ),
            ),
            actions: [
              TextButton(
                onPressed: () => Navigator.pop(ctx),
                child: Text(
                  textCancelPicker ??
                      MaterialLocalizations.of(context).cancelButtonLabel,
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  final p = await controller
                      .getCurrentPositionAdvancedPositionPicker();
                  await controller.cancelAdvancedPositionPicker();
                  Navigator.pop(ctx, p);
                },
                child: Text(
                  textConfirmPicker ??
                      MaterialLocalizations.of(context).okButtonLabel,
                ),
              ),
            ],
          ),
        ),
      );
    },
  );

  return point;
}