Files
rive-flutter/example/lib/examples/text_runs.dart
HayesGordon 43e102c1a9 Rive flutter/release 0.14.0 dev.1 (#10178) 4b77d3dea0
* chore(flutter): remove old build scrips

* chore(flutter): fix analyzer warnings

* chore(flutter): update rive_native 0.0.4

* docs(flutter): update readme to point to legacy code

List virtualization hit testing 3 (#10157) 8b7aa84704
* feat: propagate hit tests up in the component tree to detect if they are hitting a clipped area

Fix bug with Artboard ScaleType in Lists (#10159) 8251f1b259
Fixes a bug when databinding scale type to Artboards used in Lists due to the created Artboard not knowing what it's parent's main layout axis was. We need to pass it down as soon as the artboard is created.

List fixes 2 (#10153) 8749deb70a
When virtualizing lists, there were some issues with instanced artboards not rendering correctly until the following frame. This fixes that issue, as addresses similar 1 frame delayed layout updates particularly when using nested artboards

fix: only shape text with modifiers if the shapes are not empty (#10147) 95bf14f49b

fix: include missing header for randomization (#10126) 099266fec8

fix: change keys to rcp to avoid memory issues (#10146) 11042e5b4c
change keys to rcp to avoid memory issues

List virtualization fixes (#10143) bf3b33a30a
First round of fixes for List Virtualization/Carousel

Fix layout flicker when adding a new artboard using virtualization
Fix hit detection
Fix scroll snapping not working properly in Carousel mode
Fix z-index issue with Carousel when items wrapped around from end to start.
Fix a transform issue found by @JcToon

Nnnn data biinding artboard fixes (#10139) e54d2ba962
* update overrides when artboard changes
* add nested artboard as hit component even if it does not have state machines to support data binding
* when adding a new item to a list, use the previous view model from the list as source if it exists

feature: scripting require (#10133) 496fa2b490
* fix: working on dependent imports

* feature: add full problem report to wasm

* feature: runtime require

* feature: scripting require

* chore: remove string_view

* chore: assert instead of runtime error

* chore: fix warning on windows

* chore: fix memory leak

* chore: fix unused var

* chore: more windows warnings

* chore: fix dart code_core tests

* fix: missing bool in FFI setScriptSource

List Virtualization & Scroll Carousel (#9965) d973e8c253
Add support for List virtualization as well as a parameter to the ScrollConstraint to support infinite scrolling (Carousel).

There are important caveats with Virtualization enabled:

The List instances enough artboards to fit into their parent's bounds and when not rendered, they are pooled and reused as necessary. Lists can be non-uniform meaning they can consist of more than 1 Artboard (ViewModel) type
Does not currently work when its parent is set to wrap because more complex computations may result when wrapping
In order to use Carousel, virtualization must also be enabled
Infinite scroll only works in a single direction, not both at the same time

feat(apple): add support for data binding list properties (#9936) d2997eeef4

feat: nested artboards -> components (#10082) 7379bdd49f
* publishable mixin

* only show components in nested artboard list

* updates

* icons…

* icons

* change increment to boolean

* remove lib component keys in ext

* remove icons

* flag

* remove `didPublish` property

* get this library

* fix ups

* test fixes

* flag inspcetor icons

* move publishable to custom enums

* tool icon fix

* extra flags

* use resolver to check if nestable

* panel sizes

* regen keys

* panel width core default value

Co-authored-by: Gordon <pggordonhayes@gmail.com>
2025-07-15 11:11:15 +00:00

89 lines
2.6 KiB
Dart

import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
import 'package:rive_example/main.dart' show RiveExampleApp;
/// We strongly recommend using Data Binding instead of updating text runs
/// manually. See: https://rive.app/docs/runtimes/data-binding
///
/// An example showing how to read and update text runs at runtime.
/// See: https://rive.app/docs/runtimes/text
class ExampleTextRuns extends StatefulWidget {
const ExampleTextRuns({super.key});
@override
State<ExampleTextRuns> createState() => _ExampleTextRunsState();
}
class _ExampleTextRunsState extends State<ExampleTextRuns> {
File? _riveFile;
RiveWidgetController? _controller;
Future<void> _init() async {
_riveFile = await File.asset(
'assets/electrified_button_nested_text.riv',
riveFactory: RiveExampleApp.getCurrentFactory,
assetLoader: (asset, bytes) {
if (asset is FontAsset) {
_loadFont(asset);
return true;
}
return false;
},
);
_controller = RiveWidgetController(
_riveFile!,
artboardSelector: ArtboardSelector.byName('Button'),
stateMachineSelector: StateMachineSelector.byName('button'),
);
// Read/update text runs
// You can access nested text runs by providing an optional path
final initialText =
_controller?.artboard.getText('button_text', path: null);
debugPrint('Initial text: $initialText');
_controller?.artboard.setText('button_text', 'Hello, world!');
final updatedText = _controller?.artboard.getText('button_text');
debugPrint('Updated text: $updatedText');
setState(() {});
}
@override
void initState() {
super.initState();
_init();
}
@override
void dispose() {
_controller?.dispose();
_riveFile?.dispose();
super.dispose();
}
// This example has the font asset external from the Rive file, and we're
// loading it manually. If you embedded the font in the Rive file, you can
// skip this step.
//
// See: https://rive.app/docs/runtimes/loading-assets
Future<void> _loadFont(FontAsset asset) async {
final bytes = await rootBundle.load('assets/fonts/Inter-Regular.ttf');
final font = await RiveExampleApp.getCurrentFactory
.decodeFont(bytes.buffer.asUint8List());
if (font != null && mounted) {
asset.font(font);
font.dispose();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _riveFile == null
? const SizedBox()
: RiveWidget(controller: _controller!),
);
}
}