Closed mdudek closed 3 years ago
I tried your animation in the example code with runtime 0.6.2+2 and it appears to be working fine, using Flutter stable release in the iOS simulator.
Can you supply what version of Flutter and the runtime you're using.
Here's the code in full:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _togglePlay() {
setState(() => _controller.isActive = !_controller.isActive);
}
/// Tracks if the animation is playing by whether controller is running.
bool get isPlaying => _controller?.isActive ?? false;
Artboard _riveArtboard;
RiveAnimationController _controller;
@override
void initState() {
super.initState();
// Load the animation file from the bundle, note that you could also
// download this. The RiveFile just expects a list of bytes.
rootBundle.load('assets/noAds.riv').then(
(data) async {
final file = RiveFile();
// Load the RiveFile from the binary data.
if (file.import(data)) {
// The artboard is the root of the animation and gets drawn in the
// Rive widget.
final artboard = file.mainArtboard;
// Add a controller to play back a known animation on the main/default
// artboard.We store a reference to it so we can toggle playback.
artboard.addController(_controller = SimpleAnimation('circle'));
setState(() => _riveArtboard = artboard);
}
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: _riveArtboard == null
? const SizedBox()
: Rive(artboard: _riveArtboard),
),
floatingActionButton: FloatingActionButton(
onPressed: _togglePlay,
tooltip: isPlaying ? 'Pause' : 'Play',
child: Icon(
isPlaying ? Icons.pause : Icons.play_arrow,
),
),
);
}
}
Tested on newer Flutter 1.24.0-7.0.pre on a Mac with no issues:
Happy to take a look at any example Flutter code you might have that demonstrates the issue to help get to the bottom of this.
I'm using stable Flutter 1.22.3, just tested on Android 10 emulator with rive 0.6.2+2, but doesn't work.
I have finally found the reason. I have used wrong animation name in the code:
SimpleAnimation('circle')
Thanks for help, everything works as expected.
Perfect! Glad it's working.
My rive animation displays first frame, but animation doesn't start.
The riv file is attached.
noAds.zip