Skip to content

Commit d6ea0f4

Browse files
committed
add flutter_map init
1 parent b63313b commit d6ea0f4

File tree

9 files changed

+138
-2
lines changed

9 files changed

+138
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ doc/api/
2525

2626
.flutter-plugins
2727
.flutter-plugins-dependencies
28+
lib/core/config/app_config.dart

ios/Podfile.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PODS:
2+
- Flutter (1.0.0)
3+
- geolocator_apple (1.2.0):
4+
- Flutter
5+
6+
DEPENDENCIES:
7+
- Flutter (from `Flutter`)
8+
- geolocator_apple (from `.symlinks/plugins/geolocator_apple/ios`)
9+
10+
EXTERNAL SOURCES:
11+
Flutter:
12+
:path: Flutter
13+
geolocator_apple:
14+
:path: ".symlinks/plugins/geolocator_apple/ios"
15+
16+
SPEC CHECKSUMS:
17+
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
18+
geolocator_apple: 9bcea1918ff7f0062d98345d238ae12718acfbc1
19+
20+
PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
21+
22+
COCOAPODS: 1.16.2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// You may use dotenv package instead
2+
3+
class AppConfigExample {
4+
static const String apiKey = 'Your API Key';
5+
}

lib/core/constants/colors.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ import 'package:flutter/material.dart';
33
const Color white = Colors.white;
44
const Color black = Colors.black;
55
const Color transparent = Colors.transparent;
6+
const Color red = Colors.red;

lib/core/init/app_widget.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:mapmotion_flutter/core/di/dependency_injector.dart';
44
import 'package:mapmotion_flutter/presentation/blocs/application_life_cycle/application_life_cycle_cubit.dart';
55
import 'package:mapmotion_flutter/presentation/blocs/location/location_cubit.dart';
66
import 'package:mapmotion_flutter/presentation/blocs/permission/permission_cubit.dart';
7-
import 'package:mapmotion_flutter/presentation/views/home/home_view.dart';
7+
import 'package:mapmotion_flutter/presentation/views/map/map_view.dart';
88

99
class AppWidget extends StatelessWidget {
1010
const AppWidget({super.key});
@@ -25,7 +25,7 @@ class AppWidget extends StatelessWidget {
2525
],
2626
child: const MaterialApp(
2727
debugShowCheckedModeBanner: false,
28-
home: HomeView(),
28+
home: MapView(),
2929
),
3030
);
3131
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_map/flutter_map.dart';
3+
import 'package:latlong2/latlong.dart';
4+
import 'package:mapmotion_flutter/core/config/app_config.dart';
5+
import 'package:mapmotion_flutter/presentation/views/map/widgets/center_button.dart';
6+
import 'package:mapmotion_flutter/presentation/views/map/widgets/custom_marker.dart';
7+
8+
class MapView extends StatefulWidget {
9+
const MapView({Key? key}) : super(key: key);
10+
11+
@override
12+
State<MapView> createState() => _MapViewState();
13+
}
14+
15+
class _MapViewState extends State<MapView> {
16+
final _mapController = MapController();
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
final stadiaApiKey = AppConfig.apiKey;
21+
22+
return Scaffold(
23+
appBar: AppBar(title: const Text('MapMotion Flutter')),
24+
body: Stack(
25+
alignment: Alignment.bottomCenter,
26+
children: [
27+
FlutterMap(
28+
mapController: _mapController,
29+
options: MapOptions(
30+
initialCenter: const LatLng(51.509364, -0.128928),
31+
initialZoom: 9.2,
32+
interactionOptions: const InteractionOptions(
33+
flags: InteractiveFlag.all & ~InteractiveFlag.rotate,
34+
),
35+
cameraConstraint: CameraConstraint.contain(
36+
bounds: LatLngBounds(const LatLng(-90, -180), const LatLng(90, 180)),
37+
),
38+
),
39+
children: [
40+
TileLayer(
41+
// Bring your own tiles
42+
urlTemplate: 'https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}@2x.png?api_key=$stadiaApiKey',
43+
userAgentPackageName: 'com.example.app', // Add your app identifier
44+
// And many more recommended properties!
45+
),
46+
const MarkerLayer(
47+
markers: [
48+
Marker(
49+
point: const LatLng(51.509364, -0.128928),
50+
width: 50,
51+
height: 50,
52+
child: CustomMarker(),
53+
),
54+
],
55+
),
56+
],
57+
),
58+
CenterButton(
59+
onPressed: () {
60+
_mapController.move(const LatLng(51.509364, -0.128928), 9.2);
61+
},
62+
),
63+
],
64+
),
65+
);
66+
}
67+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:mapmotion_flutter/core/constants/colors.dart';
3+
4+
class CenterButton extends StatelessWidget {
5+
const CenterButton({Key? key, required this.onPressed}) : super(key: key);
6+
7+
final VoidCallback onPressed;
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return Padding(
12+
padding: const EdgeInsets.only(bottom: 28),
13+
child: OutlinedButton(
14+
onPressed: onPressed,
15+
child: const Text('Center'),
16+
style: ButtonStyle(
17+
backgroundColor: WidgetStateProperty.all(white),
18+
),
19+
),
20+
);
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:mapmotion_flutter/core/constants/colors.dart';
3+
4+
class CustomMarker extends StatelessWidget {
5+
const CustomMarker({Key? key}) : super(key: key);
6+
7+
@override
8+
Widget build(BuildContext context) {
9+
return Container(
10+
width: 50,
11+
height: 50,
12+
decoration: const BoxDecoration(color: red, shape: BoxShape.circle),
13+
child: const Icon(Icons.person),
14+
);
15+
}
16+
}

pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies:
2222
geolocator: ^13.0.2
2323
equatable: ^2.0.7
2424
flutter_bloc: ^9.0.0
25+
flutter_map: ^8.0.0
26+
latlong2: ^0.9.1
2527
cupertino_icons: ^1.0.8
2628

2729
dev_dependencies:

0 commit comments

Comments
 (0)