diff --git a/example/lib/main.dart b/example/lib/main.dart index 51d4126..cbdd03f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -46,7 +46,8 @@ class MyApp extends StatelessWidget { onError: (context, error) {}, getCurrentLocation: _getCurrentLocationUsingLocationPackage, reverseZoom: ReverseZoom.suburb, - getLocationStream: () => location.onLocationChanged.map((event) => LatLng(event.latitude!, event.longitude!)), + getLocationStream: () => location.onLocationChanged + .map((event) => LatLng(event.latitude!, event.longitude!)), child: MaterialApp( title: 'Flutter Demo', locale: const Locale("ar"), @@ -105,10 +106,12 @@ class _MyHomePageState extends State { } void showPicker(BuildContext context) { - Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) { + Navigator.of(context) + .push(MaterialPageRoute(builder: (BuildContext context) { return OpenStreetMaps( options: OpenMapOptions(), - bloc: CustomBloc(const OpenMapState.selected(SelectedLocation.single(null))), + bloc: CustomBloc( + const OpenMapState.selected(SelectedLocation.single(null))), ); })); } diff --git a/lib/src/bloc.dart b/lib/src/bloc.dart index c655189..989954d 100644 --- a/lib/src/bloc.dart +++ b/lib/src/bloc.dart @@ -12,7 +12,8 @@ abstract class OpenMapBloc { @freezed class OpenMapState with _$OpenMapState { const factory OpenMapState.selected(SelectedLocation selected) = _Selected; - const factory OpenMapState.reversing(SelectedLocation selected, LatLng reversing) = _Reversing; + const factory OpenMapState.reversing( + SelectedLocation selected, LatLng reversing) = _Reversing; const factory OpenMapState.searching({ required SelectedLocation selected, @@ -30,5 +31,6 @@ class OpenMapState with _$OpenMapState { @freezed class SelectedLocation with _$SelectedLocation { const factory SelectedLocation.single(FormattedLocation? selected) = _Single; - const factory SelectedLocation.multi(List selected) = _Multi; + const factory SelectedLocation.multi(List selected) = + _Multi; } diff --git a/lib/src/location_model.dart b/lib/src/location_model.dart index f8c9500..4c95bd2 100644 --- a/lib/src/location_model.dart +++ b/lib/src/location_model.dart @@ -89,22 +89,27 @@ class FormattedLocation with _$FormattedLocation { return FormattedLocation( placeId: json["place_id"]!.toString(), address: Address.fromMap(json["address"] ?? {}), - names: (json["namedetails"] as Map).map((key, value) => MapEntry(key.toString(), value)), + names: (json["namedetails"] as Map) + .map((key, value) => MapEntry(key.toString(), value)), lat: double.parse(json['lat']?.toString() ?? ''), lon: double.parse(json['lon']?.toString() ?? ''), addresstype: json["addresstype"] ?? '', boundingbox: LatLngBounds.fromPoints([ - LatLng(double.parse(boundingBox[0].toString()), double.parse(boundingBox[2].toString())), - LatLng(double.parse(boundingBox[1].toString()), double.parse(boundingBox[3].toString())), + LatLng(double.parse(boundingBox[0].toString()), + double.parse(boundingBox[2].toString())), + LatLng(double.parse(boundingBox[1].toString()), + double.parse(boundingBox[3].toString())), ]), category: json["category"] ?? '', displayName: json["display_name"] ?? '', - extratags: (json["extratags"] as Map).map((key, value) => MapEntry(key.toString(), value)), + extratags: (json["extratags"] as Map) + .map((key, value) => MapEntry(key.toString(), value)), geojson: GeoGeometry.fromMap(json["geojson"]), importance: double.parse(json["importance"]?.toString() ?? ''), licence: json["licence"] ?? '', name: json["name"] ?? '', - namedetails: (json["namedetails"] as Map).map((key, value) => MapEntry(key.toString(), value)), + namedetails: (json["namedetails"] as Map) + .map((key, value) => MapEntry(key.toString(), value)), osmId: int.parse(json["osm_id"]?.toString() ?? '0'), osmType: json["osm_type"] ?? '', placeRank: int.parse(json["place_rank"]?.toString() ?? '0'), @@ -156,17 +161,21 @@ class Address { class GeoGeometry with _$GeoGeometry { const GeoGeometry._(); factory GeoGeometry.point(LatLng point, Color randomColor) = GeoPoint; - factory GeoGeometry.linestring(List points, Color randomColor) = GeoLinestring; - factory GeoGeometry.polygon(List points, Color randomColor) = GeoPolygon; + factory GeoGeometry.linestring(List points, Color randomColor) = + GeoLinestring; + factory GeoGeometry.polygon(List points, Color randomColor) = + GeoPolygon; static GeoGeometry fromMap(Map json) { var coords = json["coordinates"] as List; - var color = Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0); + var color = + Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0); if (json["type"] == "Polygon") { var points = coords.map((e) { return (e as List).map((e) => _latLng(e)).toList(); }).toList(); - return GeoGeometry.polygon(points.expand((element) => element).toList(), color); + return GeoGeometry.polygon( + points.expand((element) => element).toList(), color); } else if (json["type"] == "LineString") { var points = coords.map((e) => _latLng(e)).toList(); return GeoGeometry.linestring(points, color); diff --git a/lib/src/location_picker_field.dart b/lib/src/location_picker_field.dart index 562472c..e8a967d 100644 --- a/lib/src/location_picker_field.dart +++ b/lib/src/location_picker_field.dart @@ -12,7 +12,8 @@ import 'options.dart'; class _BaseFormField extends StatefulWidget { final T? intialValue; - final Function(FormFieldState field, SelectedLocation selectedLocation) onDone; + final Function(FormFieldState field, SelectedLocation selectedLocation) + onDone; final FormFieldSetter? onSaved; final FormFieldValidator? validator; final InputDecoration decoration; @@ -99,12 +100,14 @@ class __BaseFormFieldState extends State<_BaseFormField> { initialValue: widget.intialValue, onSaved: widget.onSaved, builder: (FormFieldState field) { - var effectiveDecoration = widget.decoration.applyDefaults(Theme.of(context).inputDecorationTheme); + var effectiveDecoration = widget.decoration + .applyDefaults(Theme.of(context).inputDecorationTheme); var removeIcon = widget.removeIcon; var _showRemove = !widget.isEmpty(field.value) && removeIcon != null; effectiveDecoration = effectiveDecoration.copyWith( errorText: field.errorText, - prefixIcon: effectiveDecoration.prefixIcon ?? const Icon(Icons.my_location_rounded), + prefixIcon: effectiveDecoration.prefixIcon ?? + const Icon(Icons.my_location_rounded), suffixIcon: _showRemove ? IconButton( onPressed: () { @@ -206,7 +209,8 @@ class OpenMapPicker extends StatelessWidget { expands: expands, focusNode: focusNode, intialValue: intialValue, - options: (FormattedLocation? value) => OpenMapOptions(center: value?.toLatLng()), + options: (FormattedLocation? value) => + OpenMapOptions(center: value?.toLatLng()), onDone: (field, value) { field.didChange(value.whenOrNull( single: (selected) { @@ -265,7 +269,8 @@ class MultiOpenMapPicker extends StatelessWidget { @override Widget build(BuildContext context) { return _BaseFormField>( - state: (value) => OpenMapState.selected(SelectedLocation.multi(value ?? [])), + state: (value) => + OpenMapState.selected(SelectedLocation.multi(value ?? [])), decoration: decoration, display: (value) { var v = value ?? []; @@ -296,7 +301,9 @@ class MultiOpenMapPicker extends StatelessWidget { if (list.isEmpty) { return OpenMapOptions(); } else { - return OpenMapOptions.bounds(bounds: LatLngBounds.fromPoints(list.map((e) => e.toLatLng()).toList())); + return OpenMapOptions.bounds( + bounds: LatLngBounds.fromPoints( + list.map((e) => e.toLatLng()).toList())); } }, onDone: (field, value) { @@ -327,7 +334,8 @@ class _OpenMapBloc extends OpenMapBloc { _OpenMapBloc(this._state); @override OpenMapState get state => _state; - final StreamController _controller = StreamController.broadcast(); + final StreamController _controller = + StreamController.broadcast(); @override Stream get stream => _controller.stream; diff --git a/lib/src/map_app_bar.dart b/lib/src/map_app_bar.dart index 32ca50c..c6fbceb 100644 --- a/lib/src/map_app_bar.dart +++ b/lib/src/map_app_bar.dart @@ -66,7 +66,8 @@ class _MapAppBarState extends State { "polygon_geojson": "1", "extratags": "1", "polygon_threshold": "1", - if (widget.searchFilters != null) ...(widget.searchFilters!.toJson()) + if (widget.searchFilters != null) + ...(widget.searchFilters!.toJson()) }, ); var response = await http.get(url); diff --git a/lib/src/map_view.dart b/lib/src/map_view.dart index 28a964e..b6b02ac 100644 --- a/lib/src/map_view.dart +++ b/lib/src/map_view.dart @@ -4,7 +4,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_map/plugin_api.dart'; import 'package:http/http.dart' as http; -import 'package:positioned_tap_detector_2/positioned_tap_detector_2.dart'; import './location_model.dart'; import './map_app_bar.dart'; @@ -18,7 +17,8 @@ import 'reverse_options.dart'; import 'selected_location_view.dart'; import 'shapes.dart'; -typedef MyLocationButtonCallBack = Widget Function(Function(LatLng destLocation, [double destZoom]) callback); +typedef MyLocationButtonCallBack = Widget Function( + Function(LatLng destLocation, [double destZoom]) callback); /// Map screen /// - it can be used to display location @@ -85,7 +85,8 @@ class OpenStreetMaps extends StatefulWidget { _OpenStreetMapsState createState() => _OpenStreetMapsState(); } -class _OpenStreetMapsState extends State with TickerProviderStateMixin { +class _OpenStreetMapsState extends State + with TickerProviderStateMixin { late final _MapControllerImpl _controller; late final _MyAnimationController _animationController; @override @@ -128,14 +129,15 @@ class _OpenStreetMapsState extends State with TickerProviderStat return res.copyWith( lat: loc.latitude, lon: loc.longitude, - geojson: GeoGeometry.linestring([...line.points, loc], line.randomColor), + geojson: + GeoGeometry.linestring([...line.points, loc], line.randomColor), ); }, polygon: (polygon) => res, ); } - void _onTap(TapPosition position, LatLng latLng) async { + void _onTap(LatLng latLng) async { var bloc = widget.bloc; if (bloc != null) { var _oldState = bloc.state; @@ -148,9 +150,13 @@ class _OpenStreetMapsState extends State with TickerProviderStat bloc.emit(OpenMapState.selected(SelectedLocation.single(result))); }, multi: (old) { - var exists = old.any((element) => element.identifier == result.identifier); - var _new = - exists ? old.map((e) => e.identifier == result.identifier ? result : e).toList() : [result, ...old]; + var exists = + old.any((element) => element.identifier == result.identifier); + var _new = exists + ? old + .map((e) => e.identifier == result.identifier ? result : e) + .toList() + : [result, ...old]; bloc.emit(OpenMapState.selected(SelectedLocation.multi(_new))); }, ); @@ -164,7 +170,8 @@ class _OpenStreetMapsState extends State with TickerProviderStat } } - void _onMapCreated(MapController controller, OpenMapSettings? settings) async { + void _onMapCreated( + MapController controller, OpenMapSettings? settings) async { try { if (settings?.getCurrentLocation != null) { if (widget.options.center != null) return; @@ -206,7 +213,8 @@ class _OpenStreetMapsState extends State with TickerProviderStat _animationController.addListener(() { if (mounted) { _controller.move( - LatLng(_latTween.evaluate(animation), _lngTween.evaluate(animation)), + LatLng( + _latTween.evaluate(animation), _lngTween.evaluate(animation)), _zoomTween.evaluate(animation), ); } @@ -253,7 +261,7 @@ class _OpenStreetMapsState extends State with TickerProviderStat var options = widget.options.create( controller: _controller, onMapCreated: (_) => _onMapCreated(_, settings), - onTap: _onTap, + onTap: (_, pos) => _onTap(pos), ); var bloc = widget.bloc; if (bloc == null) return _buildMap(options, settings); @@ -266,9 +274,12 @@ class _OpenStreetMapsState extends State with TickerProviderStat moveTo: moveTo, onDone: widget.onDone, searchFilters: widget.searchFilters ?? settings?.searchFilters, - srearchHint: widget.srearchHint ?? settings?.srearchHint?.call(context) ?? 'Search here', + srearchHint: widget.srearchHint ?? + settings?.srearchHint?.call(context) ?? + 'Search here', ), - bottomNavigationBar: SelectedLocationView(bloc: bloc, fitBounds: fitBounds), + bottomNavigationBar: + SelectedLocationView(bloc: bloc, fitBounds: fitBounds), floatingActionButton: _myCurrentLocation, resizeToAvoidBottomInset: false, body: _buildMap(options, settings), @@ -304,7 +315,9 @@ class _OpenStreetMapsState extends State with TickerProviderStat child: tileWidget, ); }, - tileProvider: widget.tileProvider ?? settings?.defaultTileProvider ?? const NonCachingNetworkTileProvider(), + tileProvider: widget.tileProvider ?? + settings?.defaultTileProvider ?? + const NonCachingNetworkTileProvider(), ), ), ], @@ -315,7 +328,8 @@ class _OpenStreetMapsState extends State with TickerProviderStat MapPolylines(bloc: widget.bloc!), MapMarkers(bloc: widget.bloc!), ], - if (settings?.currentLocationMarker != null || settings?.getLocationStream != null) + if (settings?.currentLocationMarker != null || + settings?.getLocationStream != null) const MyCurrentLocationMarker() ], ); @@ -323,7 +337,8 @@ class _OpenStreetMapsState extends State with TickerProviderStat } class _MyAnimationController extends AnimationController { - _MyAnimationController(TickerProvider vsync) : super(vsync: vsync, duration: const Duration(milliseconds: 400)); + _MyAnimationController(TickerProvider vsync) + : super(vsync: vsync, duration: const Duration(milliseconds: 400)); @override void reset() { diff --git a/lib/src/map_view_settings.dart b/lib/src/map_view_settings.dart index d983677..405bfc5 100644 --- a/lib/src/map_view_settings.dart +++ b/lib/src/map_view_settings.dart @@ -9,8 +9,10 @@ import 'reverse_options.dart'; typedef GetCurrentLocationCallBack = Future Function(); typedef GetLocationStreamCallBack = Stream Function(); -typedef LocationMarkerCallback = Marker Function(BuildContext context, FormattedLocation location); -typedef CurrentLocationMarkerCallback = Marker Function(BuildContext context, LatLng location); +typedef LocationMarkerCallback = Marker Function( + BuildContext context, FormattedLocation location); +typedef CurrentLocationMarkerCallback = Marker Function( + BuildContext context, LatLng location); /// global settings for map /// You can wrap material app with it or wrap entire screen to ovveride the globals diff --git a/lib/src/markers.dart b/lib/src/markers.dart index 9929264..bcc9499 100644 --- a/lib/src/markers.dart +++ b/lib/src/markers.dart @@ -12,7 +12,8 @@ class MyCurrentLocationMarker extends StatefulWidget { const MyCurrentLocationMarker({Key? key}) : super(key: key); @override - _MyCurrentLocationMarkerState createState() => _MyCurrentLocationMarkerState(); + _MyCurrentLocationMarkerState createState() => + _MyCurrentLocationMarkerState(); } class _MyCurrentLocationMarkerState extends State { @@ -32,7 +33,8 @@ class _MyCurrentLocationMarkerState extends State { } if (settings?.getLocationStream != null) { _lisner = settings!.getLocationStream!().listen((event) { - if (_currentLocation?.latitude == event.latitude && _currentLocation?.longitude == event.longitude) { + if (_currentLocation?.latitude == event.latitude && + _currentLocation?.longitude == event.longitude) { return; } if (mounted) { @@ -67,7 +69,8 @@ class _MyCurrentLocationMarkerState extends State { borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( - color: Theme.of(context).primaryColor.withOpacity(0.5), + color: + Theme.of(context).primaryColor.withOpacity(0.5), blurRadius: 5, ) ], @@ -101,7 +104,8 @@ class MapMarkers extends StatelessWidget { } else { var loading = currentState.whenOrNull(reversing: (_, r) => r); return currentState.selected.when( - single: (value) => _markers(context, value == null ? [] : [value], loading), + single: (value) => + _markers(context, value == null ? [] : [value], loading), multi: (values) => _markers(context, values, loading), ); } @@ -109,7 +113,8 @@ class MapMarkers extends StatelessWidget { ); } - Widget _markers(BuildContext context, List locations, LatLng? loadingPoint) { + Widget _markers(BuildContext context, List locations, + LatLng? loadingPoint) { var settings = OpenMapSettings.of(context); var marker = settings?.locationMarker; return MarkerLayerWidget( diff --git a/lib/src/options.dart b/lib/src/options.dart index 74d0ed2..1b20339 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -177,20 +177,26 @@ class OpenMapOptions { required TapCallback onTap, OpenMapSettings? settings, }) { - var def = settings?.defaultOptions - ?.create(onMapCreated: onMapCreated, controller: controller, onTap: onTap, settings: null) ?? + var def = settings?.defaultOptions?.create( + onMapCreated: onMapCreated, + controller: controller, + onTap: onTap, + settings: null) ?? MapOptions(); return MapOptions( allowPanning: allowPanning ?? def.allowPanning, - allowPanningOnScrollingParent: allowPanningOnScrollingParent ?? def.allowPanningOnScrollingParent, + allowPanningOnScrollingParent: + allowPanningOnScrollingParent ?? def.allowPanningOnScrollingParent, crs: crs ?? def.crs, center: _center ?? def.center, bounds: _bounds ?? def.bounds, boundsOptions: _boundsOptions ?? def.boundsOptions, zoom: zoom ?? def.zoom, rotation: rotation ?? def.rotation, - debugMultiFingerGestureWinner: debugMultiFingerGestureWinner ?? def.debugMultiFingerGestureWinner, - enableMultiFingerGestureRace: enableMultiFingerGestureRace ?? def.enableMultiFingerGestureRace, + debugMultiFingerGestureWinner: + debugMultiFingerGestureWinner ?? def.debugMultiFingerGestureWinner, + enableMultiFingerGestureRace: + enableMultiFingerGestureRace ?? def.enableMultiFingerGestureRace, rotationThreshold: rotationThreshold ?? def.rotationThreshold, rotationWinGestures: rotationWinGestures ?? def.rotationWinGestures, pinchZoomThreshold: pinchZoomThreshold ?? def.pinchZoomThreshold, @@ -248,8 +254,10 @@ class OpenMapOptions { crs: crs ?? this.crs, zoom: zoom ?? this.zoom, rotation: rotation ?? this.rotation, - debugMultiFingerGestureWinner: debugMultiFingerGestureWinner ?? this.debugMultiFingerGestureWinner, - enableMultiFingerGestureRace: enableMultiFingerGestureRace ?? this.enableMultiFingerGestureRace, + debugMultiFingerGestureWinner: + debugMultiFingerGestureWinner ?? this.debugMultiFingerGestureWinner, + enableMultiFingerGestureRace: + enableMultiFingerGestureRace ?? this.enableMultiFingerGestureRace, rotationThreshold: rotationThreshold ?? this.rotationThreshold, rotationWinGestures: rotationWinGestures ?? this.rotationWinGestures, pinchZoomThreshold: pinchZoomThreshold ?? this.pinchZoomThreshold, @@ -261,7 +269,8 @@ class OpenMapOptions { maxZoom: maxZoom ?? this.maxZoom, interactiveFlags: interactiveFlags ?? this.interactiveFlags, allowPanning: allowPanning ?? this.allowPanning, - allowPanningOnScrollingParent: allowPanningOnScrollingParent ?? this.allowPanningOnScrollingParent, + allowPanningOnScrollingParent: + allowPanningOnScrollingParent ?? this.allowPanningOnScrollingParent, onLongPress: onLongPress ?? this.onLongPress, onPositionChanged: onPositionChanged ?? this.onPositionChanged, plugins: plugins ?? this.plugins, @@ -278,8 +287,10 @@ class OpenMapOptions { crs: crs ?? this.crs, zoom: zoom ?? this.zoom, rotation: rotation ?? this.rotation, - debugMultiFingerGestureWinner: debugMultiFingerGestureWinner ?? this.debugMultiFingerGestureWinner, - enableMultiFingerGestureRace: enableMultiFingerGestureRace ?? this.enableMultiFingerGestureRace, + debugMultiFingerGestureWinner: + debugMultiFingerGestureWinner ?? this.debugMultiFingerGestureWinner, + enableMultiFingerGestureRace: + enableMultiFingerGestureRace ?? this.enableMultiFingerGestureRace, rotationThreshold: rotationThreshold ?? this.rotationThreshold, rotationWinGestures: rotationWinGestures ?? this.rotationWinGestures, pinchZoomThreshold: pinchZoomThreshold ?? this.pinchZoomThreshold, @@ -291,7 +302,8 @@ class OpenMapOptions { maxZoom: maxZoom ?? this.maxZoom, interactiveFlags: interactiveFlags ?? this.interactiveFlags, allowPanning: allowPanning ?? this.allowPanning, - allowPanningOnScrollingParent: allowPanningOnScrollingParent ?? this.allowPanningOnScrollingParent, + allowPanningOnScrollingParent: + allowPanningOnScrollingParent ?? this.allowPanningOnScrollingParent, onLongPress: onLongPress ?? this.onLongPress, onPositionChanged: onPositionChanged ?? this.onPositionChanged, plugins: plugins ?? this.plugins, diff --git a/lib/src/reverse_options.dart b/lib/src/reverse_options.dart index 8dc396d..506e721 100644 --- a/lib/src/reverse_options.dart +++ b/lib/src/reverse_options.dart @@ -57,7 +57,8 @@ class SearchFilters { Map toJson() { return { if (countryCodes != null) "countrycodes": countryCodes!.join(','), - if (excludePlaceIds != null) "exclude_place_ids": excludePlaceIds!.join(','), + if (excludePlaceIds != null) + "exclude_place_ids": excludePlaceIds!.join(','), if (limit != null) "limit": limit!.toString(), if (viewBox != null) ...(viewBox!.toJson()), if (email != null) "email": email!, @@ -69,12 +70,14 @@ class SearchFilters { class ViewBox extends LatLngBounds { final bool bounded; - ViewBox(LatLng southWest, LatLng northEast, [this.bounded = false]) : super(southWest, northEast); + ViewBox(LatLng southWest, LatLng northEast, [this.bounded = false]) + : super(southWest, northEast); Map toJson() { return { "bounded": bounded ? "1" : "0", - "viewbox": "${southWest?.latitude},${southWest?.longitude},${northEast?.latitude},${northEast?.longitude}", + "viewbox": + "${southWest?.latitude},${southWest?.longitude},${northEast?.latitude},${northEast?.longitude}", }; } } diff --git a/lib/src/search_results.dart b/lib/src/search_results.dart index 7fabae5..135dc49 100644 --- a/lib/src/search_results.dart +++ b/lib/src/search_results.dart @@ -7,7 +7,8 @@ import 'bloc.dart'; class SearchResults extends StatelessWidget { final OpenMapBloc bloc; final ValueChanged fitBounds; - const SearchResults({Key? key, required this.bloc, required this.fitBounds}) : super(key: key); + const SearchResults({Key? key, required this.bloc, required this.fitBounds}) + : super(key: key); @override Widget build(BuildContext context) { @@ -20,15 +21,18 @@ class SearchResults extends StatelessWidget { return type.maybeMap( orElse: () => _buildBody(context, [], type), searching: (search) => _buildBody(context, search.oldResults, search), - results: (results) => _buildBody(context, results.searchResults, results), + results: (results) => + _buildBody(context, results.searchResults, results), ); }, ); } - ConstrainedBox _buildBody(BuildContext context, List results, OpenMapState state) { + ConstrainedBox _buildBody(BuildContext context, + List results, OpenMapState state) { return ConstrainedBox( - constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height / 2), + constraints: + BoxConstraints(maxHeight: MediaQuery.of(context).size.height / 2), child: AnimatedSize( duration: const Duration(milliseconds: 300), alignment: Alignment.topCenter, @@ -50,12 +54,19 @@ class SearchResults extends StatelessWidget { onTap: () { state.selected.when( single: (_) { - bloc.emit(OpenMapState.selected(SelectedLocation.single(loc))); + bloc.emit( + OpenMapState.selected(SelectedLocation.single(loc))); }, multi: (old) { - var exists = old.any((element) => element.identifier == loc.identifier); - var _new = exists ? old.map((e) => e.identifier == loc.identifier ? loc : e).toList() : [loc, ...old]; - bloc.emit(OpenMapState.selected(SelectedLocation.multi(_new))); + var exists = old + .any((element) => element.identifier == loc.identifier); + var _new = exists + ? old + .map((e) => e.identifier == loc.identifier ? loc : e) + .toList() + : [loc, ...old]; + bloc.emit( + OpenMapState.selected(SelectedLocation.multi(_new))); }, ); fitBounds(loc.boundingbox); diff --git a/lib/src/selected_location_view.dart b/lib/src/selected_location_view.dart index 6fbb1fb..c8cf81f 100644 --- a/lib/src/selected_location_view.dart +++ b/lib/src/selected_location_view.dart @@ -8,7 +8,9 @@ class SelectedLocationView extends StatelessWidget { final OpenMapBloc bloc; final ValueChanged fitBounds; - const SelectedLocationView({Key? key, required this.bloc, required this.fitBounds}) : super(key: key); + const SelectedLocationView( + {Key? key, required this.bloc, required this.fitBounds}) + : super(key: key); @override Widget build(BuildContext context) { @@ -19,17 +21,20 @@ class SelectedLocationView extends StatelessWidget { child: StreamBuilder( stream: bloc.stream, initialData: bloc.state, - builder: (BuildContext context, AsyncSnapshot snapshot) { + builder: + (BuildContext context, AsyncSnapshot snapshot) { var selected = snapshot.data!.selected; return selected.when( multi: (List values) { return ConstrainedBox( - constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height / 3), + constraints: BoxConstraints( + maxHeight: MediaQuery.of(context).size.height / 3), child: Scrollbar( child: ListView( shrinkWrap: true, children: ListTile.divideTiles( - tiles: values.map((e) => _buildTile(context, e, selected)), + tiles: + values.map((e) => _buildTile(context, e, selected)), context: context, ).toList(), ), @@ -47,7 +52,8 @@ class SelectedLocationView extends StatelessWidget { ); } - Widget _buildTile(BuildContext context, FormattedLocation e, SelectedLocation state) { + Widget _buildTile( + BuildContext context, FormattedLocation e, SelectedLocation state) { return ListTile( title: Text(e.toString()), leading: const Icon(Icons.pin_drop), @@ -56,10 +62,12 @@ class SelectedLocationView extends StatelessWidget { onPressed: () { state.when( single: (sub) { - bloc.emit(const OpenMapState.selected(SelectedLocation.single(null))); + bloc.emit( + const OpenMapState.selected(SelectedLocation.single(null))); }, multi: (list) { - bloc.emit(OpenMapState.selected(SelectedLocation.multi(list.where((element) => element != e).toList()))); + bloc.emit(OpenMapState.selected(SelectedLocation.multi( + list.where((element) => element != e).toList()))); }, ); }, diff --git a/lib/src/shapes.dart b/lib/src/shapes.dart index 05b738d..0116cf0 100644 --- a/lib/src/shapes.dart +++ b/lib/src/shapes.dart @@ -104,7 +104,8 @@ class GeoGeometryGroup { class _MapShapes extends StatelessWidget { final OpenMapBloc bloc; final Widget Function(GeoGeometryGroup group, LatLng? loadingPoint) builder; - const _MapShapes({Key? key, required this.bloc, required this.builder}) : super(key: key); + const _MapShapes({Key? key, required this.bloc, required this.builder}) + : super(key: key); @override Widget build(BuildContext context) { diff --git a/pubspec.yaml b/pubspec.yaml index 24f1bbe..9100399 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: open_location_picker -description: A new Flutter package project. +description: FormField to pick one or more locations from open streat map version: 0.0.1 -# homepage: +homepage: https://github.com/mo-ah-dawood/open_location_picker environment: sdk: ">=2.15.0 <3.0.0" @@ -13,6 +13,7 @@ dependencies: flutter_map: ^0.14.0 freezed_annotation: ^1.1.0 http: ^0.13.4 + latlong2: ^0.8.1