showSimplePickerLocation function

Future<GeoPoint?> showSimplePickerLocation({
  1. required BuildContext context,
  2. Widget? titleWidget,
  3. PickerMarkerBuilder? pickMarkerWidget,
  4. String? title,
  5. TextStyle? titleStyle,
  6. String? textConfirmPicker,
  7. String? textCancelPicker,
  8. EdgeInsets contentPadding = EdgeInsets.zero,
  9. double radius = 0.0,
  10. GeoPoint? initPosition,
  11. ZoomOption zoomOption = const ZoomOption(),
  12. bool isDismissible = false,
  13. 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

The dialog is design-system neutral. Labels default to English ('OK' and 'Cancel'); pass translated labels for other locales.

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;
  // Labels are caller-localizable; no MaterialLocalizations are required.
  GeoPoint? point = await showGeneralDialog<GeoPoint>(
    barrierDismissible: isDismissible,
    barrierLabel: textCancelPicker ?? 'Cancel',
    context: context,
    pageBuilder: (ctx, animation, secondaryAnimation) {
      return PopScope(
        canPop: isDismissible,
        child: SafeArea(
          child: Center(
            child: Container(
              margin: const EdgeInsets.all(24),
              decoration: BoxDecoration(
                color: const Color(0xFFFFFFFF),
                borderRadius: BorderRadius.circular(radius),
              ),
              clipBehavior: Clip.antiAlias,
              child: DefaultTextStyle(
                style: const TextStyle(color: Color(0xFF000000), fontSize: 14),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    if (title != null || titleWidget != null)
                      Padding(
                        padding: const EdgeInsets.all(16),
                        child: title != null
                            ? Text(title, style: titleStyle)
                            : titleWidget,
                      ),
                    Padding(
                      padding: contentPadding,
                      child: 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),
                                ),
                              ],
                            );
                          },
                        ),
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(8),
                      child: Wrap(
                        alignment: WrapAlignment.end,
                        children: [
                          _PickerButton(
                            onPressed: () => Navigator.pop(ctx),
                            child: Text(textCancelPicker ?? 'Cancel'),
                          ),
                          _PickerButton(
                            onPressed: () async {
                              final center = await controller.centerMap;
                              if (!ctx.mounted) return;
                              Navigator.pop(ctx, center);
                            },
                            child: Text(textConfirmPicker ?? 'OK'),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
    },
  );

  return point;
}