Files
rive-flutter/example/lib/examples/pause_play.dart
HayesGordon f43cac5221 fix(rive_flutter): draw at least one frame on active false (#10241) 2002fefe40
* fix(rive_flutter): draw at least one frame on active false

* chore: single line boolean operation

* chore: update CHANGELOG

feat: add support for artboard style overrides in lists (#10212) ca58369fb6
add support for artboard style overrides in lists

chore: refactor scripting api (#10218) 85aa06d5db
* chore: explicit vec2D.xy and origin

* chore: reworking color api

* chore: refactor mat2d

* chore: add paint.with and paint.new

* feature: working on exposing builtin definitions

* chore: cleanup

* fix: removing unused var

* fix: bad api call

* chore: missed file

Co-authored-by: Gordon <pggordonhayes@gmail.com>
2025-07-27 08:09:53 +00:00

79 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
import 'package:rive_example/main.dart' show RiveExampleApp;
class ExamplePausePlay extends StatefulWidget {
const ExamplePausePlay({super.key});
@override
State<ExamplePausePlay> createState() => _ExamplePausePlayState();
}
class _ExamplePausePlayState extends State<ExamplePausePlay> {
final fileLoader = FileLoader.fromAsset(
'assets/rewards.riv',
riveFactory: RiveExampleApp.getCurrentFactory,
);
late RiveWidgetController controller;
bool isPlaying = false;
@override
void initState() {
super.initState();
}
void togglePlayPause() {
setState(() {
isPlaying = !isPlaying;
controller.active = isPlaying;
});
}
@override
void dispose() {
fileLoader.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: RiveWidgetBuilder(
fileLoader: fileLoader,
dataBind: DataBind.auto(),
onLoaded: (state) {
controller = state.controller;
controller.active = isPlaying;
},
builder: (context, state) => switch (state) {
RiveLoading() => const Center(
child: Center(child: CircularProgressIndicator()),
),
RiveFailed() => ErrorWidget.withDetails(
message: state.error.toString(),
error: FlutterError(state.error.toString()),
),
RiveLoaded() => RiveWidget(
controller: state.controller,
fit: Fit.layout,
layoutScaleFactor: 1 / 3,
)
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton.icon(
onPressed: togglePlayPause,
icon: Icon(isPlaying ? Icons.pause : Icons.play_arrow),
label: Text(isPlaying ? 'Pause' : 'Play'),
),
),
],
);
}
}