Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major State Refactoring #1551

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4cd53e8
Split FlutterMapState in to a stateful container widget (FlutterMapSt…
rorystephenson Jun 7, 2023
41a41af
Extract interactions to InteractionDetector
rorystephenson Jun 9, 2023
afa3c78
Move gesture initialisation out of builder and stop passing the whole…
rorystephenson Jun 9, 2023
f389195
Minor tidy-ups
rorystephenson Jun 9, 2023
ff484a1
Re-instate linking of MapController to map state
rorystephenson Jun 9, 2023
0746a0b
Trigger all FlutterMapState manipulations via FlutterMapStateController
rorystephenson Jun 9, 2023
8be935b
Reduce MapController API size and simplify gesture code
rorystephenson Jun 10, 2023
21ae265
Remove unnecessary getters now that InteractiveFlags defines convenie…
rorystephenson Jun 10, 2023
5d4298c
Fix double tap zoom not working when drag was enabled and prevent pin…
rorystephenson Jun 10, 2023
b1fba18
Use new InteractiveFlag convenience methods
rorystephenson Jun 10, 2023
32d57e0
Combine getBoundsCenterZoom and centerZoomFitBounds
rorystephenson Jun 11, 2023
3bc6ca4
Replace http stubbing with an in-memory TileProvider in tests
rorystephenson Jun 11, 2023
0a9a05f
Separate MapOptions from FlutterMapState
rorystephenson Jun 11, 2023
d5a8acb
Combine adaptive bounds, max bounds and sw/ne pan bounds in to a sing…
rorystephenson Jun 13, 2023
8ac52f9
Create FrameConstraint and FrameFit abstraction
rorystephenson Jun 14, 2023
d16bc55
Add deprecations on MapControllerImpl
rorystephenson Jun 14, 2023
dae90c8
Add fitting by coordinates
rorystephenson Jun 14, 2023
f4d5a04
Rename FlutterMapState to FlutterMapFrame, add InteractionOptions col…
rorystephenson Jun 14, 2023
66e508d
Use InhertiedModel instead of InheritedWidget
rorystephenson Jun 15, 2023
ced3a03
Remove FitCoordinates' inside parameter because fitting inside a set …
rorystephenson Jun 15, 2023
24263d2
Fix event names appearing minified when running web release build
rorystephenson Jun 15, 2023
f5f5735
Set constraints that match the old adaptive constraints
rorystephenson Jun 15, 2023
3cbea21
Make documentation easier to read
rorystephenson Jun 15, 2023
b7b5bf2
Use flags/options from InteractionOptions not the old deprecated valu…
rorystephenson Jun 15, 2023
4e60392
Fix options propagation
rorystephenson Jun 15, 2023
3e4413c
Add tests to make sure the InheritedModel notifies if and only if the…
rorystephenson Jun 15, 2023
3a0c0bb
Rename FlutterMapFrame to MapFrame
rorystephenson Jun 15, 2023
ccea34a
Avoid an extra Stack
rorystephenson Jun 15, 2023
bdae8ef
Assign AnimationControllers where they are declared
rorystephenson Jun 19, 2023
4dedb1c
Rename from frame to camera
rorystephenson Jun 20, 2023
b743773
Remove flutter_map_ prefixes from files in lib/src/map/
rorystephenson Jun 20, 2023
7f0a386
Move FlutterMapStateContainer in to FlutterMap's file since it is jus…
rorystephenson Jun 20, 2023
4c99df7
Rename mapCamera variables to camera for consistency with options for…
rorystephenson Jun 20, 2023
cbf26b4
Documentation
rorystephenson Jun 20, 2023
354e6d3
Use standard deprecations format
rorystephenson Jun 20, 2023
dabf734
Re-organized camera related source files
JaffaKetchup Jun 21, 2023
9e775c6
Add FitInsideBounds
jjoelson Jun 23, 2023
955e066
Move CameraFit attributes from the base class to the subclasses and t…
rorystephenson Jun 27, 2023
2b40381
Re-order imports alphabetically
rorystephenson Jun 27, 2023
d0ad93c
Add lint to enforce consistent import/export ordering
rorystephenson Jun 27, 2023
5750b6a
Reinstate maxBounds as a deprecated option
rorystephenson Jun 27, 2023
5d8aca1
Remove duplicate exports and make imports consistent
rorystephenson Jun 27, 2023
f986d77
Remove deprecated AnchorAlign
rorystephenson Jul 5, 2023
f5d6d13
Add deprecation for nonrotatedSize
rorystephenson Jul 5, 2023
150213e
Fix deprecation
rorystephenson Jul 5, 2023
c327723
Set default CameraFit maxZoom values to null
rorystephenson Jul 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linter:
avoid_dynamic_calls: true
cancel_subscriptions: true
close_sinks: true
directives_ordering: true
package_api_docs: true
prefer_constructors_over_static_methods: true
prefer_final_in_for_each: true
Expand All @@ -25,4 +26,4 @@ linter:
throw_in_finally: true
type_annotate_public_apis: true
unnecessary_statements: true
use_named_constants: true
use_named_constants: true
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';

import 'package:flutter_map_example/pages/animated_map_controller.dart';
import 'package:flutter_map_example/pages/circle.dart';
import 'package:flutter_map_example/pages/custom_crs/custom_crs.dart';
Expand Down
28 changes: 15 additions & 13 deletions example/lib/pages/animated_map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
void _animatedMapMove(LatLng destLocation, double destZoom) {
// Create some tweens. These serve to split up the transition from one location to another.
// In our case, we want to split the transition be<tween> our current map center and the destination.
final camera = mapController.camera;
final latTween = Tween<double>(
begin: mapController.center.latitude, end: destLocation.latitude);
begin: camera.center.latitude, end: destLocation.latitude);
final lngTween = Tween<double>(
begin: mapController.center.longitude, end: destLocation.longitude);
final zoomTween = Tween<double>(begin: mapController.zoom, end: destZoom);
begin: camera.center.longitude, end: destLocation.longitude);
final zoomTween = Tween<double>(begin: camera.zoom, end: destZoom);

// Create a animation controller that has a duration and a TickerProvider.
final controller = AnimationController(
Expand Down Expand Up @@ -161,10 +162,10 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
london,
]);

mapController.fitBounds(
bounds,
options: const FitBoundsOptions(
padding: EdgeInsets.only(left: 15, right: 15),
mapController.fitCamera(
CameraFit.bounds(
bounds: bounds,
padding: const EdgeInsets.symmetric(horizontal: 15),
),
);
},
Expand All @@ -178,9 +179,10 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
london,
]);

final centerZoom =
mapController.centerZoomFitBounds(bounds);
_animatedMapMove(centerZoom.center, centerZoom.zoom);
final constrained = CameraFit.bounds(
bounds: bounds,
).fit(mapController.camera);
_animatedMapMove(constrained.center, constrained.zoom);
},
child: const Text('Fit Bounds animated'),
),
Expand All @@ -190,9 +192,9 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
Flexible(
child: FlutterMap(
mapController: mapController,
options: MapOptions(
center: const LatLng(51.5, -0.09),
zoom: 5,
options: const MapOptions(
initialCenter: LatLng(51.5, -0.09),
initialZoom: 5,
maxZoom: 10,
minZoom: 3),
children: [
Expand Down
6 changes: 3 additions & 3 deletions example/lib/pages/circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class CirclePage extends StatelessWidget {
),
Flexible(
child: FlutterMap(
options: MapOptions(
center: const LatLng(51.5, -0.09),
zoom: 11,
options: const MapOptions(
initialCenter: LatLng(51.5, -0.09),
initialZoom: 11,
),
children: [
TileLayer(
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/custom_crs/custom_crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class _CustomCrsPageState extends State<CustomCrsPage> {
options: MapOptions(
// Set the default CRS
crs: epsg3413CRS,
center: LatLng(point.x, point.y),
zoom: 3,
initialCenter: LatLng(point.x, point.y),
initialZoom: 3,
// Set maxZoom usually scales.length - 1 OR resolutions.length - 1
// but not greater
maxZoom: maxZoom,
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/epsg3413_crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class _EPSG3413PageState extends State<EPSG3413Page> {
child: FlutterMap(
options: MapOptions(
crs: epsg3413CRS,
center: const LatLng(90, 0),
zoom: 3,
initialCenter: const LatLng(90, 0),
initialZoom: 3,
maxZoom: maxZoom,
),
nonRotatedChildren: [
Expand Down
10 changes: 5 additions & 5 deletions example/lib/pages/epsg4326_crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class EPSG4326Page extends StatelessWidget {
),
Flexible(
child: FlutterMap(
options: MapOptions(
options: const MapOptions(
minZoom: 0,
crs: const Epsg4326(),
center: const LatLng(0, 0),
zoom: 0,
crs: Epsg4326(),
initialCenter: LatLng(0, 0),
initialZoom: 0,
),
children: [
TileLayer(
Expand All @@ -37,7 +37,7 @@ class EPSG4326Page extends StatelessWidget {
layers: ['TOPO-OSM-WMS'],
),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
)
),
],
),
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/fallback_url.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class FallbackUrlPage extends StatelessWidget {
Flexible(
child: FlutterMap(
options: MapOptions(
center: center,
zoom: zoom,
initialCenter: center,
initialZoom: zoom,
maxZoom: maxZoom,
minZoom: minZoom,
),
Expand Down
12 changes: 7 additions & 5 deletions example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ class _HomePageState extends State<HomePage> {
Flexible(
child: FlutterMap(
options: MapOptions(
center: const LatLng(51.5, -0.09),
zoom: 5,
maxBounds: LatLngBounds(
const LatLng(-90, -180),
const LatLng(90, 180),
initialCenter: const LatLng(51.5, -0.09),
initialZoom: 5,
cameraConstraint: CameraConstraint.contain(
bounds: LatLngBounds(
const LatLng(-90, -180),
const LatLng(90, 180),
),
),
),
nonRotatedChildren: [
Expand Down
81 changes: 62 additions & 19 deletions example/lib/pages/interactive_test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
void onMapEvent(MapEvent mapEvent) {
if (mapEvent is! MapEventMove && mapEvent is! MapEventRotate) {
// do not flood console with move and rotate events
debugPrint(mapEvent.toString());
debugPrint(_eventName(mapEvent));
}

setState(() {
Expand Down Expand Up @@ -59,7 +59,7 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
MaterialButton(
color: InteractiveFlag.hasFlag(flags, InteractiveFlag.drag)
color: InteractiveFlag.hasDrag(flags)
? Colors.greenAccent
: Colors.redAccent,
onPressed: () {
Expand All @@ -70,8 +70,7 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
child: const Text('Drag'),
),
MaterialButton(
color: InteractiveFlag.hasFlag(
flags, InteractiveFlag.flingAnimation)
color: InteractiveFlag.hasFlingAnimation(flags)
? Colors.greenAccent
: Colors.redAccent,
onPressed: () {
Expand All @@ -82,10 +81,9 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
child: const Text('Fling'),
),
MaterialButton(
color:
InteractiveFlag.hasFlag(flags, InteractiveFlag.pinchMove)
? Colors.greenAccent
: Colors.redAccent,
color: InteractiveFlag.hasPinchMove(flags)
? Colors.greenAccent
: Colors.redAccent,
onPressed: () {
setState(() {
updateFlags(InteractiveFlag.pinchMove);
Expand All @@ -99,8 +97,7 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
MaterialButton(
color: InteractiveFlag.hasFlag(
flags, InteractiveFlag.doubleTapZoom)
color: InteractiveFlag.hasDoubleTapZoom(flags)
? Colors.greenAccent
: Colors.redAccent,
onPressed: () {
Expand All @@ -111,7 +108,7 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
child: const Text('Double tap zoom'),
),
MaterialButton(
color: InteractiveFlag.hasFlag(flags, InteractiveFlag.rotate)
color: InteractiveFlag.hasRotate(flags)
? Colors.greenAccent
: Colors.redAccent,
onPressed: () {
Expand All @@ -122,10 +119,9 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
child: const Text('Rotate'),
),
MaterialButton(
color:
InteractiveFlag.hasFlag(flags, InteractiveFlag.pinchZoom)
? Colors.greenAccent
: Colors.redAccent,
color: InteractiveFlag.hasPinchZoom(flags)
? Colors.greenAccent
: Colors.redAccent,
onPressed: () {
setState(() {
updateFlags(InteractiveFlag.pinchZoom);
Expand All @@ -139,7 +135,7 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: Center(
child: Text(
'Current event: ${_latestEvent?.runtimeType ?? "none"}\nSource: ${_latestEvent?.source ?? "none"}',
'Current event: ${_eventName(_latestEvent)}\nSource: ${_latestEvent?.source.name ?? "none"}',
textAlign: TextAlign.center,
),
),
Expand All @@ -148,9 +144,11 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
child: FlutterMap(
options: MapOptions(
onMapEvent: onMapEvent,
center: const LatLng(51.5, -0.09),
zoom: 11,
interactiveFlags: flags,
initialCenter: const LatLng(51.5, -0.09),
initialZoom: 11,
interactionOptions: InteractionOptions(
flags: flags,
),
),
children: [
TileLayer(
Expand All @@ -166,4 +164,49 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
),
);
}

String _eventName(MapEvent? event) {
switch (event) {
case MapEventTap():
return 'MapEventTap';
case MapEventSecondaryTap():
return 'MapEventSecondaryTap';
case MapEventLongPress():
return 'MapEventLongPress';
case MapEventMove():
return 'MapEventMove';
case MapEventMoveStart():
return 'MapEventMoveStart';
case MapEventMoveEnd():
return 'MapEventMoveEnd';
case MapEventFlingAnimation():
return 'MapEventFlingAnimation';
case MapEventFlingAnimationNotStarted():
return 'MapEventFlingAnimationNotStarted';
case MapEventFlingAnimationStart():
return 'MapEventFlingAnimationStart';
case MapEventFlingAnimationEnd():
return 'MapEventFlingAnimationEnd';
case MapEventDoubleTapZoom():
return 'MapEventDoubleTapZoom';
case MapEventScrollWheelZoom():
return 'MapEventScrollWheelZoom';
case MapEventDoubleTapZoomStart():
return 'MapEventDoubleTapZoomStart';
case MapEventDoubleTapZoomEnd():
return 'MapEventDoubleTapZoomEnd';
case MapEventRotate():
return 'MapEventRotate';
case MapEventRotateStart():
return 'MapEventRotateStart';
case MapEventRotateEnd():
return 'MapEventRotateEnd';
case MapEventNonRotatedSizeChange():
return 'MapEventNonRotatedSizeChange';
case null:
return 'null';
default:
return 'Unknown';
}
}
JaffaKetchup marked this conversation as resolved.
Show resolved Hide resolved
}
21 changes: 12 additions & 9 deletions example/lib/pages/latlng_to_screen_point.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/widgets/drawer.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_example/widgets/drawer.dart';
import 'package:latlong2/latlong.dart';

class LatLngScreenPointTestPage extends StatefulWidget {
Expand Down Expand Up @@ -36,23 +36,24 @@ class _LatLngScreenPointTestPageState extends State<LatLngScreenPointTestPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('LatLng To Screen Point')),
drawer: buildDrawer(context, LatLngScreenPointTestPage.route),
body: Stack(children: [
appBar: AppBar(title: const Text('LatLng To Screen Point')),
drawer: buildDrawer(context, LatLngScreenPointTestPage.route),
body: Stack(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: FlutterMap(
mapController: _mapController,
options: MapOptions(
onMapEvent: onMapEvent,
onTap: (tapPos, latLng) {
final pt1 = _mapController.latLngToScreenPoint(latLng);
final pt1 = _mapController.camera.latLngToScreenPoint(latLng);
_textPos = CustomPoint(pt1.x, pt1.y);
setState(() {});
},
center: const LatLng(51.5, -0.09),
zoom: 11,
rotation: 0,
initialCenter: const LatLng(51.5, -0.09),
initialZoom: 11,
initialRotation: 0,
),
children: [
TileLayer(
Expand All @@ -68,6 +69,8 @@ class _LatLngScreenPointTestPageState extends State<LatLngScreenPointTestPage> {
width: 20,
height: 20,
child: const FlutterLogo())
]));
],
),
);
}
}
10 changes: 6 additions & 4 deletions example/lib/pages/many_markers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ class _ManyMarkersPageState extends State<ManyMarkersPage> {
Text('$_sliderVal markers'),
Flexible(
child: FlutterMap(
options: MapOptions(
center: const LatLng(50, 20),
zoom: 5,
interactiveFlags: InteractiveFlag.all - InteractiveFlag.rotate,
options: const MapOptions(
initialCenter: LatLng(50, 20),
initialZoom: 5,
interactionOptions: InteractionOptions(
flags: InteractiveFlag.all - InteractiveFlag.rotate,
),
),
children: [
TileLayer(
Expand Down
Loading
Loading