我想使用像这样的rive动画我注意到这个画板包含一些NestedArtboard这个嵌套画板没有

我想使用像这样的 rive 动画

我注意到这个画板包含一些 NestedArtboard 这个嵌套画板没有被我的应用加载,我想知道为什么会这样?

这是我的代码:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';
class RiveBackground extends StatefulWidget {
  const RiveBackground({Key? key}) : super(key: key);
  @override
  State createState() => _RiveBackgroundState();
}
class _RiveBackgroundState extends State {
  // Declarations necessary to rive
  final riveFileName = 'assets/rive/last.riv';
  Artboard? globalArtboard;
  // Animation controller
  late RiveAnimationController _animationController;
  // Loads a Rive file
  Future _loadRiveFile() async {
    final bytes = await rootBundle.load(riveFileName);
    RiveFile rFile = RiveFile.import(bytes);
    final artboard = rFile.artboardByName('Motion');
    print(globalArtboard);
    globalArtboard = artboard!
      ..addController(
        _animationController = SimpleAnimation('Animation 1'),
      );
    setState(() {});
  }
 
  @override
  void initState() {
    WidgetsBinding.instance!.addPostFrameCallback((_) => _loadRiveFile());
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    print('Building');
    return Scaffold(
      body: globalArtboard != null
          ? Container(
              height: MediaQuery.of(context).size.height,
              width: MediaQuery.of(context).size.width,
              child: Rive(
                fit: BoxFit.cover,
                artboard: globalArtboard!,
              ),
            )
          : const Center(child: Text('empty')),
    );
  }
}

预期结果

我的结果

© 版权声明
THE END
喜欢就支持一下吧
点赞91赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容