简体   繁体   English

使用 controller 参数 flutter 时 Flare Actor 突然消失

[英]Flare Actor suddenly disappears when using controller parameter flutter

I tried using flare in my application to design an rating screen with a progress bar in it and I am encountering an error "whenever I try to add controller parameter the flare suddenly disappears" with an error.我尝试在我的应用程序中使用flare 来设计一个带有进度条的评分屏幕,但我遇到了一个错误“每当我尝试添加controller 参数时,flare 就会突然消失”并出现错误。

The getter 'duration' was called on null.在 null 上调用了 getter 'duration'。

Receiver: null接收器:null

Tried calling: duration尝试调用:持续时间

I have attached the required code below我在下面附上了所需的代码

  FlareRateController _flareController;

void updateDragPosition(Offset offset) {
    setState(() {
      _dragPercent = (offset.dx / sliderWidth).clamp(0.0, 1.0);
      _flareController.updatePercent(_dragPercent);
    });
  }

void initState() {
    super.initState();
    _flareController = FlareRateController();
    SystemChrome.setEnabledSystemUIOverlays([]);
  }

_buildFlareActor() => SizedBox(
        width: 1100.w,
        height: 680.h,
        child: FlareActor(
          "assets/rate.flr",
          artboard: "Artboard",
          controller: _flareController,
        ),
      );

The FlareRatecontroller class is FlareRatecontroller class 是

class FlareRateController extends FlareController {
  FlutterActorArtboard _artboard;
  ActorAnimation _rateAnimation;

  double _slidePercent = 0.0;
  double _currentSlide = 0.0;
  double _smoothTime = 5;

  void updatePercent(double val) {
    _slidePercent = val;
  }

  @override
  void initialize(FlutterActorArtboard artboard) {
    if (artboard.name.compareTo("Artboard") == 0) {
      _artboard = artboard;
      _rateAnimation = artboard.getAnimation("Slide");
    }
  }

  @override
  bool advance(FlutterActorArtboard artboard, double elapsed) {
    if (artboard.name.compareTo("Artboard") == 0) {
      _currentSlide += (_slidePercent - _currentSlide) *
          math.min(
            1,
            elapsed * _smoothTime,
          );
      _rateAnimation.apply(
          _currentSlide * _rateAnimation.duration, artboard, 1); //error here in duration
    }
    return true;
  }

  @override
  void setViewTransform(Mat2D viewTransform) {
    // TODO: implement setViewTransform
  }
}

the error is in _rateAnimation.duration (already commented the lie)错误在 _rateAnimation.duration 中(已经评论了谎言)

Your Flare Actor disappears because the propertie "duration" return null您的 Flare Actor 消失了,因为属性“持续时间”返回 null

I found this rate app speed code and copy, because i need more information about the code.我找到了这个速率应用程序速度代码并复制,因为我需要有关代码的更多信息。 That's what i found:这就是我发现的:

Your code is getting animation for your ActorAnimation like "Slide".您的代码正在为您的 ActorAnimation 获取 animation,例如“Slide”。 Try changing the "Slide" parameter and set "slide" (s in lower case)尝试更改“Slide”参数并设置“slide”(s 小写)

Then run your app again and tell me if u got it.然后再次运行你的应用程序并告诉我你是否得到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM