-
-
Notifications
You must be signed in to change notification settings - Fork 871
/
Copy pathcancellable_tile_provider.dart
74 lines (69 loc) · 2.65 KB
/
cancellable_tile_provider.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_cancellable_tile_provider/flutter_map_cancellable_tile_provider.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:flutter_map_example/widgets/notice_banner.dart';
import 'package:latlong2/latlong.dart';
class CancellableTileProviderPage extends StatefulWidget {
static const String route = '/cancellable_tile_provider_page';
const CancellableTileProviderPage({super.key});
@override
State<CancellableTileProviderPage> createState() =>
_CancellableTileProviderPageState();
}
class _CancellableTileProviderPageState
extends State<CancellableTileProviderPage> {
bool _providerEnabled = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Cancellable Tile Provider')),
drawer: const MenuDrawer(CancellableTileProviderPage.route),
body: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: SwitchListTile.adaptive(
title: const Text('Use CancellableNetworkTileProvider'),
value: _providerEnabled,
onChanged: (value) => setState(() => _providerEnabled = value),
),
),
),
const NoticeBanner.recommendation(
text:
'This tile provider cancels unnecessary HTTP requests, which can help performance (especially on the web)',
url:
'https://docs.fleaflet.dev/layers/tile-layer/tile-providers#cancellablenetworktileprovider',
sizeTransition: 905,
),
Expanded(
child: FlutterMap(
options: MapOptions(
initialCenter: const LatLng(51.5, -0.09),
initialZoom: 5,
cameraConstraint: CameraConstraint.contain(
bounds: LatLngBounds(
const LatLng(-90, -180),
const LatLng(90, 180),
),
),
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
tileProvider: _providerEnabled
? CancellableNetworkTileProvider()
: null,
),
],
),
),
],
),
);
}
}