0

I'm quite new to Flutter / Dart and previously generated Apps using Cordova (JS).

Now I'm trying to build an app with Flutter and the flutter-maplibre-gl package. I already got my map inside the app with the default MapLibre world map. Now I'm trying to change the language used for the country name labels. I found the method setMapLanguage, but can't figure out how and where to use it. This is my code so far:

import 'package:flutter/material.dart';
import 'package:maplibre_gl/mapbox_gl.dart';

class FullScreenMap extends StatefulWidget {
  @override
  State<FullScreenMap> createState() => _FullScreenMapState();
}

class _FullScreenMapState extends State<FullScreenMap> {
  MaplibreMapController? mapController;

  void _onMapCreated(MaplibreMapController controller) {
    mapController = controller;
  }

  void _onMapClicked() {
    mapController!.setMapLanguage('name_de');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: MaplibreMap(
        onMapCreated: _onMapCreated,
        initialCameraPosition: const CameraPosition(
          target: LatLng(0.0, 0.0),
          zoom: 3
          ),
          rotateGesturesEnabled: false,
          trackCameraPosition: true,
          onMapClick: (point, latLng) {
            print(point);
            print(latLng);
            _onMapClicked();
          },
        )
    );
  }
}

Because later I want to be able to change the language via button click, I'm testing it with onMapClick right now. I also checked the documentation, but can't figure out how to read it (maybe I'm too stucked in my JavaScript thinking).

Any tips / hints / examples would help. Or if you have tips for general tutorials that could help me understanding how to work with flutter / dart, I would be very thankful.

Hollul
  • 319
  • 4
  • 16

0 Answers0