flutter Map 4.0.0 사용방법

황인호·2023년 5월 19일
0

이전에 Flutter 1.1.1 버전 사용방법을 올린적이있다

이번에는 4.0.0 사용방법이다.

앞부분은 이전과 동일하고 코드만 일부 바뀌었다.

map.dart

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';

class AppConstants {
  static const String mapBoxAccessToken =
      'AccessToken';
  static const String mapBoxStyleId = 'YOURID';

  static final myLocation = LatLng(51.5090214, -0.1982948);
}

class MyMap extends StatefulWidget {
  const MyMap({super.key});

  @override
  State<MyMap> createState() => _MyMapState();
}

class _MyMapState extends State<MyMap> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: const Color.fromARGB(255, 33, 32, 32),
        title: const Text('Flutter MapBox'),
      ),
      body: Stack(
        children: [
          FlutterMap(
            options: MapOptions(
              zoom: 13,
              center: LatLng(37.537, 127.089),
            ),
            children: [
              TileLayer(
                urlTemplate:
                    "mapbox 지도 URL",
              ),
            ],
          ),
        ],
      ),
    );
  }
}

어디가 바뀌었냐면 이전에 layers 에서 -> children 으로

그리고 TileLayerOption -> TileLayer 로 변경되었다.

profile
성장중인 백엔드 개발자!!

0개의 댓글