Flutter Openstreet Map _mapcontroller анимация перемещения - PullRequest
0 голосов
/ 11 апреля 2020

Я использую пакет флаттера с открытыми картами улиц. Все хорошо, но когда я использую контроллер для перемещения на новое место, это делается в кратчайшие сроки. Мне нужна легкая анимация, когда карта будет перемещаться из текущей позиции в новую. Как мне создать анимацию?

Я пытался использовать контроллер анимации, кривые замедления и анимацию. В методе сборки я попробовал этот способ (отображается только для увеличения)

 _mapController.onReady.then((result) {
        LatLng TL = _mapController.bounds.northWest;
        LatLng TR = _mapController.bounds.northEast;
        LatLng BL = _mapController.bounds.southWest;
        LatLng BR = _mapController.bounds.southWest;

        LatLng currentCenter = LatLng((TL.latitude + BR.latitude) / 2,
            (TL.longitude + TR.longitude) / 2);
        double currentZoomLevel = _mapController.zoom;
        print("zoomLevel " + currentZoomLevel.toString());
        Tween<double> latTween = Tween(begin: currentCenter.latitude, end: 51.5)             
        Tween<double> lonTween = Tween(begin: currentCenter.longitude, end: -0.09)
        Tween<double> zoomTween = Tween(begin: currentZoomLevel, end: 13);
        if (_animationStatus == AnimationStatus.completed) {
          controller.reverse();
          if (currentZoomLevel != 13) {
            controller.addListener(() {
                currentZoomLevel = zoomTween.evaluate(animation);
                print(currentZoomLevel);
                print(controller.value.toString() + " " + animation.value.toString());
            });
          }
        } else if (_animationStatus == AnimationStatus.dismissed) {
          controller.forward();
          if (currentZoomLevel != 13) {
              controller.addListener(() {
                currentZoomLevel = zoomTween.evaluate(animation);
                print(currentZoomLevel);
                print(controller.value.toString() + " " + animation.value.toString());
            });
          }
        } else if (_animationStatus == null) {
          controller.forward();
          if (currentZoomLevel != 13) {
            controller.addListener(() {
                currentZoomLevel = zoomTween.evaluate(animation);
                print(currentZoomLevel);
                print(controller.value.toString() + " " + animation.value.toString());
            });
          }
        }
      });
    },

В первый раз он работает нормально, но через некоторое время контроллер, кажется, дает некоторые абсурдные значения, такие как:

I/flutter ( 8924): 0.0 0.0
I/flutter ( 8924): 0.0 0.0
I/flutter ( 8924): 0.068336 0.009261056780815125
I/flutter ( 8924): 0.068336 0.009261056780815125
I/flutter ( 8924): 0.0958215 0.0182105153799057
I/flutter ( 8924): 0.0958215 0.0182105153799057
I/flutter ( 8924): 0.123279 0.029928013682365417
I/flutter ( 8924): 0.123279 0.029928013682365417
I/flutter ( 8924): 0.187374 0.07191753387451172
.
.
.
I/flutter ( 8924): 0.919029 0.9873563051223755
I/flutter ( 8924): 0.919029 0.9873563051223755
I/flutter ( 8924): 0.956476 0.996379017829895
I/flutter ( 8924): 0.956476 0.996379017829895
I/flutter ( 8924): 0.956476 0.996379017829895
I/flutter ( 8924): 0.956476 0.996379017829895
I/flutter ( 8924): 1.0 1.0
I/flutter ( 8924): 1.0 1.0

Как вы можете дублировать значения есть. И самое главное, количество значений не 60, иногда 30, иногда 42. Я не понимаю, что происходит. Пожалуйста, помогите мне.

Найдите полный код (хотя это кажется уродливым, я изучал библиотеку, но код будет работать и воспроизводить):

https://gist.github.com/epsi95/f2398b5edc6ae0132891e3735d2d7f4d

...