Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified example/assets/layout_test.riv
Binary file not shown.
10 changes: 9 additions & 1 deletion example/lib/examples/responsive_layouts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ExampleResponsiveLayouts extends StatefulWidget {
}

class _ExampleResponsiveLayoutsState extends State<ExampleResponsiveLayouts> {
late ViewModelInstance viewModelInstance;

late final fileLoader = FileLoader.fromAsset(
'assets/layout_test.riv',
// Choose which renderer to use
Expand All @@ -21,13 +23,19 @@ class _ExampleResponsiveLayoutsState extends State<ExampleResponsiveLayouts> {
void dispose() {
// This widget state owns the file loader, dispose it.
fileLoader.dispose();
viewModelInstance.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the builder to create the viewModelInstance you also don't need to dispose it here. The builder will dispose.

super.dispose();
}

void _onLoaded(RiveLoaded state) {
viewModelInstance = state.controller.dataBind(DataBind.auto());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah didn't notice this last time, you can remove this, and instead provide the dataBind property to RiveWidgetBuilder.

Then in onLoad, you can do state.viewModelInstance to access it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh because it's a new commit, that's why I didn't notice this :)

}

@override
Widget build(BuildContext context) {
return RiveWidgetBuilder(
fileLoader: fileLoader,
onLoaded: _onLoaded,
builder: (context, state) => switch (state) {
RiveLoading() => const Center(
child: Center(child: CircularProgressIndicator()),
Expand All @@ -39,7 +47,7 @@ class _ExampleResponsiveLayoutsState extends State<ExampleResponsiveLayouts> {
RiveLoaded() => RiveWidget(
controller: state.controller,
fit: Fit.layout, // pass Fit.layout to use Rive's layout system
// layoutScaleFactor: 1 / 2, // Optionally: scale the layout
layoutScaleFactor: 1 / 2, // Optionally: scale the layout
)
},
);
Expand Down