Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unexpected reset of the attributionButtonPosition after setState #417

Open
Linker-123 opened this issue May 17, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Linker-123
Copy link

Linker-123 commented May 17, 2024

Platforms

web

Version of flutter maplibre_gl

0.18.0

Bug Description

The attributionButtonPosition parameter in the options of the map is ignored when calling setState on the widget, the parameter is specified as following:

Scaffold(

    ....

    body: MaplibreMap(
        ....
        attributionButtonPosition: AttributionButtonPosition.TopLeft,
        ....
    )

);

The full project to reproduce the issue can be seen on the following repository: https://github.com/Linker-123/maplibre-attribution-issue

Steps to Reproduce

Press the floating action button in the code sample - the attribution button will move to the bottom right corner, instead of staying at the TopLeft position.

Expected Results

Expected behavior: attributionButtonPosition == AttributionButtonPosition.TopLeft

Actual Results

After calling setState() for the whole Scaffold page, attributionButtonPosition in MaplibreMap() object becomes equal default value, e.i. attributionButtonPosition==AttributionButtonPosition.BottomRight.

Code Sample

import 'package:flutter/material.dart';

import 'package:maplibre_gl/maplibre_gl.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  MaplibreMapController? mapController;
  final double _targetLat = 40.730610;
  final double _targetLon = -73.935242;

  bool _tilt = false;
  final double _zoom = 15;

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: MaplibreMap(
        onMapCreated: _onMapCreated,
        initialCameraPosition: CameraPosition(target: LatLng(_targetLat, _targetLon), zoom: _zoom),
        attributionButtonPosition: AttributionButtonPosition.TopLeft,
        myLocationEnabled: false,
        compassEnabled: false,
        zoomGesturesEnabled: _tilt,
        styleString: "assets/osm_style.json",
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          setState(() {
            _tilt = !_tilt;
          });
          await mapController!.animateCamera(
            CameraUpdate.newCameraPosition(CameraPosition(
              target: LatLng(_targetLat, _targetLon),
              zoom: _zoom,
              tilt: 75.0,
            )),
            duration: const Duration(milliseconds: 500),
          );
        },
        child: const Icon(Icons.navigation),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    );
  }
}
@Linker-123 Linker-123 added the bug Something isn't working label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant