Flutter Openstreet Map _mapcontroller“移动”动画

问题描述 投票:0回答:1

我正在使用带有开放街道地图的Flutter Map软件包。一切都很好,但是当我使用控制器移动到新位置时,它很快就完成了。我想要一个easyinout动画,其中地图将从当前位置移动到新位置。如何创建动画?

我尝试使用动画控制器,缓入曲线和补间。在构建方法中,我尝试过这种方式(仅显示缩放)

 _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

flutter animation openstreetmap flutter-animation tween
1个回答
0
投票

我已经实现了动画:找到要点:https://gist.github.com/epsi95/98e6759aca5f5047a6a086e04b9c510e

© www.soinside.com 2019 - 2024. All rights reserved.