-
-
Notifications
You must be signed in to change notification settings - Fork 897
Expand file tree
/
Copy pathhome.dart
More file actions
95 lines (87 loc) · 3.05 KB
/
home.dart
File metadata and controls
95 lines (87 loc) · 3.05 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/widgets/drawer/floating_menu_button.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:flutter_map_example/widgets/first_start_dialog.dart';
import 'package:latlong2/latlong.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
class HomePage extends StatefulWidget {
static const String route = '/';
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
showIntroDialogIfNeeded();
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: const MenuDrawer(HomePage.route),
body: Stack(
children: [
FlutterMap(
options: const MapOptions(
initialCenter: LatLng(51.5, -0.09),
initialZoom: 5,
),
children: [
RasterTileLayer.simple(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
uaIdentifier: 'dev.fleaflet.flutter_map.demo',
rasterOptions: RasterTileLayerOptions(
paintTile: (canvas, size, tileCoordinates, tileData,
tilePaint, drawImage) {
drawImage();
},
),
),
RichAttributionWidget(
popupInitialDisplayDuration: const Duration(seconds: 5),
animationConfig: const ScaleRAWA(),
showFlutterMapAttribution: false,
attributions: [
TextSourceAttribution(
'OpenStreetMap contributors',
onTap: () async => launchUrl(
Uri.parse('https://openstreetmap.org/copyright'),
),
),
const TextSourceAttribution(
'This attribution is the same throughout this app, except '
'where otherwise specified',
prependCopyright: false,
),
],
),
],
),
const FloatingMenuButton()
],
),
);
}
void showIntroDialogIfNeeded() {
const seenIntroBoxKey = 'seenIntroBox(a)';
if (kIsWeb && Uri.base.host.trim() == 'demo.fleaflet.dev') {
SchedulerBinding.instance.addPostFrameCallback(
(_) async {
final prefs = await SharedPreferences.getInstance();
if (prefs.getBool(seenIntroBoxKey) ?? false) return;
if (!mounted) return;
await showDialog<void>(
context: context,
builder: (context) => const FirstStartDialog(),
);
await prefs.setBool(seenIntroBoxKey, true);
},
);
}
}
}