Skip to content

Commit f8d1f9f

Browse files
authoredJun 9, 2022
Deprecated old attributionBuilder (#1262)
Added new `AttributionWidget` intended as replacement Updated README & CHANGELOG Updated pubspec.yaml
1 parent 2a641e2 commit f8d1f9f

File tree

8 files changed

+163
-59
lines changed

8 files changed

+163
-59
lines changed
 

‎CHANGELOG.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
# Changelog
22

3-
## [1.0.0] - 2022
3+
## [1.1.0] - 2022
4+
5+
Contains the following additions/removals:
6+
7+
- Deprecated the existing `attributionBuilder`
8+
- Added a new method of attribution through `AttributionWidget`
9+
10+
Contains the following bug fixes:
11+
12+
- None
13+
14+
In other news:
15+
16+
- None
17+
18+
Many thanks to these contributors (in no particular order):
19+
20+
- None
21+
- ... and all the maintainers
22+
23+
---
24+
25+
## [1.0.0] - 2022/06/07
426

527
Contains the following additions/removals:
628

‎README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ Widget build(BuildContext context) {
6060
TileLayerOptions(
6161
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
6262
subdomains: ['a', 'b', 'c'],
63-
attributionBuilder: (_) {
64-
return Text("© OpenStreetMap contributors");
65-
},
6663
),
6764
MarkerLayerOptions(
6865
markers: [
@@ -78,6 +75,12 @@ Widget build(BuildContext context) {
7875
],
7976
),
8077
],
78+
nonRotatedChildren: [
79+
AttributionWidget.defaultWidget(
80+
source: 'OpenStreetMap contributors',
81+
onSourceTapped: () {},
82+
),
83+
],
8184
);
8285
}
8386
```

‎example/lib/pages/home.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ class HomePage extends StatelessWidget {
6363
urlTemplate:
6464
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
6565
subdomains: ['a', 'b', 'c'],
66-
// For example purposes. It is recommended to use
67-
// TileProvider with a caching and retry strategy, like
68-
// NetworkTileProvider or CachedNetworkTileProvider
6966
tileProvider: const NonCachingNetworkTileProvider(),
7067
),
7168
MarkerLayerOptions(markers: markers)
7269
],
70+
nonRotatedChildren: [
71+
AttributionWidget.defaultWidget(
72+
source: 'OpenStreetMap contributors',
73+
onSourceTapped: () {},
74+
),
75+
],
7376
),
7477
),
7578
],

‎lib/flutter_map.dart

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export 'package:flutter_map/src/geo/latlng_bounds.dart';
2525
export 'package:flutter_map/src/gestures/interactive_flag.dart';
2626
export 'package:flutter_map/src/gestures/map_events.dart';
2727
export 'package:flutter_map/src/gestures/multi_finger_gesture.dart';
28+
export 'package:flutter_map/src/layer/attribution_layer.dart';
2829
export 'package:flutter_map/src/layer/circle_layer.dart';
2930
export 'package:flutter_map/src/layer/group_layer.dart';
3031
export 'package:flutter_map/src/layer/layer.dart';

‎lib/src/layer/attribution_layer.dart

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:flutter/widgets.dart';
2+
3+
/// Attribution widget layer, usually placed in `nonRotatedChildren`
4+
///
5+
/// Can be anchored in a position of the map using [alignment], defaulting to [Alignment.bottomRight]. Then pass [attributionBuilder] to build your custom attribution widget.
6+
///
7+
/// Alternatively, use the constructor [defaultWidget] to get a more classic styled attibution box.
8+
class AttributionWidget extends StatelessWidget {
9+
/// Function that returns a widget given a [BuildContext], displayed on the map
10+
final WidgetBuilder attributionBuilder;
11+
12+
/// Anchor the widget in a position of the map, defaulting to [Alignment.bottomRight]
13+
final Alignment alignment;
14+
15+
/// Attribution widget layer, usually placed in `nonRotatedChildren`
16+
///
17+
/// Can be anchored in a position of the map using [alignment], defaulting to [Alignment.bottomRight]. Then pass [attributionBuilder] to build your custom attribution widget.
18+
///
19+
/// Alternatively, use the constructor [defaultWidget] to get a more classic styled attibution box.
20+
const AttributionWidget({
21+
Key? key,
22+
required this.attributionBuilder,
23+
this.alignment = Alignment.bottomRight,
24+
}) : super(key: key);
25+
26+
@override
27+
Widget build(BuildContext context) =>
28+
Align(alignment: alignment, child: attributionBuilder(context));
29+
30+
/// Quick constructor for a more classic styled attibution box
31+
///
32+
/// Displayed as a padded translucent white box with the following text: 'flutter_map | © [source]'.
33+
///
34+
/// Provide [onSourceTapped] to carry out a function when the box is tapped. If that isn't null, the source text will have [sourceTextStyle] styling - which defaults to a link styling.
35+
static Widget defaultWidget({
36+
required String source,
37+
void Function()? onSourceTapped,
38+
TextStyle sourceTextStyle = const TextStyle(color: Color(0xFF0078a8)),
39+
Alignment alignment = Alignment.bottomRight,
40+
}) =>
41+
Align(
42+
alignment: alignment,
43+
child: ColoredBox(
44+
color: const Color(0xCCFFFFFF),
45+
child: GestureDetector(
46+
onTap: onSourceTapped,
47+
child: Padding(
48+
padding: const EdgeInsets.all(3),
49+
child: Row(
50+
mainAxisSize: MainAxisSize.min,
51+
children: [
52+
const Text('flutter_map | © '),
53+
MouseRegion(
54+
cursor: onSourceTapped == null
55+
? MouseCursor.defer
56+
: SystemMouseCursors.click,
57+
child: Text(
58+
source,
59+
style: onSourceTapped == null ? null : sourceTextStyle,
60+
),
61+
),
62+
],
63+
),
64+
),
65+
),
66+
),
67+
);
68+
}

‎lib/src/layer/tile_layer/tile_layer.dart

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
202202
);
203203

204204
final attributionLayer =
205+
// ignore: deprecated_member_use_from_same_package
205206
widget.options.attributionBuilder?.call(context);
206207

207208
return Opacity(

‎lib/src/layer/tile_layer/tile_layer_options.dart

+57-51
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ class TileLayerOptions extends LayerOptions {
226226
/// When set to `true`, the `tileFadeIn*` options will be ignored.
227227
final bool fastReplace;
228228

229-
///Attribution widget builder
229+
/// [attributionBuilder] has been deprecated. Usage will continue to work, however not as expected. As an alternative, use [AttributionWidget] inside `nonRotatedChildren`.
230+
@Deprecated(
231+
'`attributionBuilder` has been deprecated. Usage will continue to work, however not as expected. As an alternative, use `AttributionWidget` inside `nonRotatedChildren`.',
232+
)
230233
final WidgetBuilder? attributionBuilder;
231234

232235
///aligment of the attribution text on the map widget
@@ -238,56 +241,59 @@ class TileLayerOptions extends LayerOptions {
238241
/// Only load tiles that are within these bounds
239242
LatLngBounds? tileBounds;
240243

241-
TileLayerOptions(
242-
{this.attributionAlignment = Alignment.bottomRight,
243-
this.attributionBuilder,
244-
Key? key,
245-
// TODO: make required
246-
this.urlTemplate,
247-
double tileSize = 256.0,
248-
double minZoom = 0.0,
249-
double maxZoom = 18.0,
250-
this.minNativeZoom,
251-
this.maxNativeZoom,
252-
this.zoomReverse = false,
253-
double zoomOffset = 0.0,
254-
Map<String, String>? additionalOptions,
255-
this.subdomains = const <String>[],
256-
this.keepBuffer = 2,
257-
this.backgroundColor = const Color(0xFFE0E0E0),
258-
@Deprecated('`placeholderImage` has been deprecated with no current replacement or workaround. Usage no longer has an effect internally.')
259-
this.placeholderImage,
260-
this.errorImage,
261-
this.tileProvider = const NonCachingNetworkTileProvider(),
262-
this.tms = false,
263-
// ignore: avoid_init_to_null
264-
this.wmsOptions = null,
265-
this.opacity = 1.0,
266-
// Tiles will not update more than once every `updateInterval` milliseconds
267-
// (default 200) when panning. It can be 0 (but it will calculating for
268-
// loading tiles every frame when panning / zooming, flutter is fast) This
269-
// can save some fps and even bandwidth (ie. when fast panning / animating
270-
// between long distances in short time)
271-
// TODO: change to Duration
272-
int updateInterval = 200,
273-
// Tiles fade in duration in milliseconds (default 100). This can be set to
274-
// 0 to avoid fade in
275-
// TODO: change to Duration
276-
int tileFadeInDuration = 100,
277-
this.tileFadeInStart = 0.0,
278-
this.tileFadeInStartWhenOverride = 0.0,
279-
this.overrideTilesWhenUrlChanges = false,
280-
this.retinaMode = false,
281-
this.errorTileCallback,
282-
Stream<void>? rebuild,
283-
this.templateFunction = util.template,
284-
this.tileBuilder,
285-
this.tilesContainerBuilder,
286-
this.evictErrorTileStrategy = EvictErrorTileStrategy.none,
287-
this.fastReplace = false,
288-
this.reset,
289-
this.tileBounds})
290-
: updateInterval =
244+
TileLayerOptions({
245+
this.attributionAlignment = Alignment.bottomRight,
246+
@Deprecated(
247+
'`attributionBuilder` has been deprecated. Usage will continue to work, however not as expected. As an alternative, use `AttributionWidget` inside `nonRotatedChildren`.',
248+
)
249+
this.attributionBuilder,
250+
Key? key,
251+
// TODO: make required
252+
this.urlTemplate,
253+
double tileSize = 256.0,
254+
double minZoom = 0.0,
255+
double maxZoom = 18.0,
256+
this.minNativeZoom,
257+
this.maxNativeZoom,
258+
this.zoomReverse = false,
259+
double zoomOffset = 0.0,
260+
Map<String, String>? additionalOptions,
261+
this.subdomains = const <String>[],
262+
this.keepBuffer = 2,
263+
this.backgroundColor = const Color(0xFFE0E0E0),
264+
@Deprecated('`placeholderImage` has been deprecated with no current replacement or workaround. Usage no longer has an effect internally.')
265+
this.placeholderImage,
266+
this.errorImage,
267+
this.tileProvider = const NonCachingNetworkTileProvider(),
268+
this.tms = false,
269+
// ignore: avoid_init_to_null
270+
this.wmsOptions = null,
271+
this.opacity = 1.0,
272+
// Tiles will not update more than once every `updateInterval` milliseconds
273+
// (default 200) when panning. It can be 0 (but it will calculating for
274+
// loading tiles every frame when panning / zooming, flutter is fast) This
275+
// can save some fps and even bandwidth (ie. when fast panning / animating
276+
// between long distances in short time)
277+
// TODO: change to Duration
278+
int updateInterval = 200,
279+
// Tiles fade in duration in milliseconds (default 100). This can be set to
280+
// 0 to avoid fade in
281+
// TODO: change to Duration
282+
int tileFadeInDuration = 100,
283+
this.tileFadeInStart = 0.0,
284+
this.tileFadeInStartWhenOverride = 0.0,
285+
this.overrideTilesWhenUrlChanges = false,
286+
this.retinaMode = false,
287+
this.errorTileCallback,
288+
Stream<void>? rebuild,
289+
this.templateFunction = util.template,
290+
this.tileBuilder,
291+
this.tilesContainerBuilder,
292+
this.evictErrorTileStrategy = EvictErrorTileStrategy.none,
293+
this.fastReplace = false,
294+
this.reset,
295+
this.tileBounds,
296+
}) : updateInterval =
291297
updateInterval <= 0 ? null : Duration(milliseconds: updateInterval),
292298
tileFadeInDuration = tileFadeInDuration <= 0
293299
? null

‎pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_map
22
description: A versatile mapping package for Flutter, based off leaflet.js, that's simple and easy to learn, yet completely customizable and configurable.
3-
version: 1.0.0
3+
version: 1.1.0
44
repository: https://github.com/fleaflet/flutter_map
55

66
environment:

0 commit comments

Comments
 (0)