More nnbd work

This commit is contained in:
Luigi Rosso
2021-03-22 21:29:26 -07:00
parent 33ad1c9ac8
commit 88541f1596
87 changed files with 563 additions and 366 deletions

View File

@ -4,7 +4,7 @@ import 'package:flutter/widgets.dart';
import 'package:rive/rive.dart';
class ExampleAnimation extends StatefulWidget {
const ExampleAnimation({Key key}) : super(key: key);
const ExampleAnimation({Key? key}) : super(key: key);
@override
_ExampleAnimationState createState() => _ExampleAnimationState();
@ -12,14 +12,17 @@ class ExampleAnimation extends StatefulWidget {
class _ExampleAnimationState extends State<ExampleAnimation> {
void _togglePlay() {
setState(() => _controller.isActive = !_controller.isActive);
if (_controller == null) {
return;
}
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;
Artboard? _riveArtboard;
RiveAnimationController? _controller;
@override
void initState() {
super.initState();
@ -51,7 +54,7 @@ class _ExampleAnimationState extends State<ExampleAnimation> {
body: Center(
child: _riveArtboard == null
? const SizedBox()
: Rive(artboard: _riveArtboard),
: Rive(artboard: _riveArtboard!),
),
floatingActionButton: FloatingActionButton(
onPressed: _togglePlay,

View File

@ -4,7 +4,7 @@ import 'package:flutter/widgets.dart';
import 'package:rive/rive.dart';
class ExampleStateMachine extends StatefulWidget {
const ExampleStateMachine({Key key}) : super(key: key);
const ExampleStateMachine({Key? key}) : super(key: key);
@override
_ExampleStateMachineState createState() => _ExampleStateMachineState();
@ -14,10 +14,10 @@ class _ExampleStateMachineState extends State<ExampleStateMachine> {
/// Tracks if the animation is playing by whether controller is running.
bool get isPlaying => _controller?.isActive ?? false;
Artboard _riveArtboard;
StateMachineController _controller;
StateMachineInput<bool> _hoverInput;
StateMachineInput<bool> _pressInput;
Artboard? _riveArtboard;
StateMachineController? _controller;
StateMachineInput<bool>? _hoverInput;
StateMachineInput<bool>? _pressInput;
@override
void initState() {
@ -56,17 +56,17 @@ class _ExampleStateMachineState extends State<ExampleStateMachine> {
child: _riveArtboard == null
? const SizedBox()
: MouseRegion(
onEnter: (_) => _hoverInput.value = true,
onExit: (_) => _hoverInput.value = false,
onEnter: (_) => _hoverInput?.value = true,
onExit: (_) => _hoverInput?.value = false,
child: GestureDetector(
onTapDown: (_) => _pressInput.value = true,
onTapCancel: () => _pressInput.value = false,
onTapUp: (_) => _pressInput.value = false,
onTapDown: (_) => _pressInput?.value = true,
onTapCancel: () => _pressInput?.value = false,
onTapUp: (_) => _pressInput?.value = false,
child: SizedBox(
width: 250,
height: 250,
child: Rive(
artboard: _riveArtboard,
artboard: _riveArtboard!,
),
),
),

View File

@ -1,12 +1,12 @@
name: rive_example
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:

View File

@ -1,10 +1,10 @@
import 'dart:collection';
import 'package:rive/src/rive_core/animation/animation.dart';
// TODO: figure out how to make this cleaner.
class AnimationList extends ListBase<Animation> {
final List<Animation> _values = [];
List<Animation> get values => _values;
// Lame way to do this due to how ListBase needs to expand a nullable list.
final List<Animation?> _values = [];
List<Animation> get values => _values.cast<Animation>();
@override
int get length => _values.length;
@ -13,7 +13,7 @@ class AnimationList extends ListBase<Animation> {
set length(int value) => _values.length = value;
@override
Animation operator [](int index) => _values[index];
Animation operator [](int index) => _values[index]!;
@override
void operator []=(int index, Animation value) => _values[index] = value;

View File

@ -3,8 +3,8 @@ import 'package:rive/src/rive_core/component.dart';
// TODO: figure out how to make this cleaner.
class ContainerChildren extends ListBase<Component> {
final List<Component> _values = [];
List<Component> get values => _values;
final List<Component?> _values = [];
List<Component> get values => _values.cast<Component>();
@override
int get length => _values.length;
@ -13,7 +13,7 @@ class ContainerChildren extends ListBase<Component> {
set length(int value) => _values.length = value;
@override
Component operator [](int index) => _values[index];
Component operator [](int index) => _values[index]!;
@override
void operator []=(int index, Component value) => _values[index] = value;

View File

@ -1,5 +1,4 @@
import 'package:rive/src/extensions.dart';
import 'package:rive/src/rive_core/animation/linear_animation.dart';
import 'package:rive/src/rive_core/animation/linear_animation_instance.dart';
import 'package:rive/src/rive_core/rive_animation_controller.dart';
import 'package:rive/src/runtime_artboard.dart';
@ -51,10 +50,7 @@ class SimpleAnimation extends RiveAnimationController<RuntimeArtboard> {
@override
bool init(RuntimeArtboard artboard) {
var animation = artboard.animationByName(animationName);
if (animation != null) {
_instance = LinearAnimationInstance(animation as LinearAnimation);
}
_instance = artboard.animationByName(animationName);
isActive = true;
return _instance != null;
}

View File

@ -28,7 +28,9 @@ abstract class AnimationBase<T extends CoreContext> extends Core<T> {
}
String from = _name;
_name = value;
nameChanged(from, value);
if (hasValidated) {
nameChanged(from, value);
}
}
void nameChanged(String from, String to);

View File

@ -35,7 +35,9 @@ abstract class AnimationStateBase extends LayerState {
}
int from = _animationId;
_animationId = value;
animationIdChanged(from, value);
if (hasValidated) {
animationIdChanged(from, value);
}
}
void animationIdChanged(int from, int to);

View File

@ -26,7 +26,9 @@ abstract class CubicInterpolatorBase<T extends CoreContext> extends Core<T> {
}
double from = _x1;
_x1 = value;
x1Changed(from, value);
if (hasValidated) {
x1Changed(from, value);
}
}
void x1Changed(double from, double to);
@ -46,7 +48,9 @@ abstract class CubicInterpolatorBase<T extends CoreContext> extends Core<T> {
}
double from = _y1;
_y1 = value;
y1Changed(from, value);
if (hasValidated) {
y1Changed(from, value);
}
}
void y1Changed(double from, double to);
@ -66,7 +70,9 @@ abstract class CubicInterpolatorBase<T extends CoreContext> extends Core<T> {
}
double from = _x2;
_x2 = value;
x2Changed(from, value);
if (hasValidated) {
x2Changed(from, value);
}
}
void x2Changed(double from, double to);
@ -86,7 +92,9 @@ abstract class CubicInterpolatorBase<T extends CoreContext> extends Core<T> {
}
double from = _y2;
_y2 = value;
y2Changed(from, value);
if (hasValidated) {
y2Changed(from, value);
}
}
void y2Changed(double from, double to);

View File

@ -28,7 +28,9 @@ abstract class KeyedObjectBase<T extends CoreContext> extends Core<T> {
}
int from = _objectId;
_objectId = value;
objectIdChanged(from, value);
if (hasValidated) {
objectIdChanged(from, value);
}
}
void objectIdChanged(int from, int to);

View File

@ -29,7 +29,9 @@ abstract class KeyedPropertyBase<T extends CoreContext> extends Core<T> {
}
int from = _propertyKey;
_propertyKey = value;
propertyKeyChanged(from, value);
if (hasValidated) {
propertyKeyChanged(from, value);
}
}
void propertyKeyChanged(int from, int to);

View File

@ -28,7 +28,9 @@ abstract class KeyFrameBase<T extends CoreContext> extends Core<T> {
}
int from = _frame;
_frame = value;
frameChanged(from, value);
if (hasValidated) {
frameChanged(from, value);
}
}
void frameChanged(int from, int to);
@ -52,7 +54,9 @@ abstract class KeyFrameBase<T extends CoreContext> extends Core<T> {
}
int from = _interpolationType;
_interpolationType = value;
interpolationTypeChanged(from, value);
if (hasValidated) {
interpolationTypeChanged(from, value);
}
}
void interpolationTypeChanged(int from, int to);
@ -75,7 +79,9 @@ abstract class KeyFrameBase<T extends CoreContext> extends Core<T> {
}
int from = _interpolatorId;
_interpolatorId = value;
interpolatorIdChanged(from, value);
if (hasValidated) {
interpolatorIdChanged(from, value);
}
}
void interpolatorIdChanged(int from, int to);

View File

@ -27,7 +27,9 @@ abstract class KeyFrameColorBase extends KeyFrame {
}
int from = _value;
_value = value;
valueChanged(from, value);
if (hasValidated) {
valueChanged(from, value);
}
}
void valueChanged(int from, int to);

View File

@ -27,7 +27,9 @@ abstract class KeyFrameDoubleBase extends KeyFrame {
}
double from = _value;
_value = value;
valueChanged(from, value);
if (hasValidated) {
valueChanged(from, value);
}
}
void valueChanged(double from, double to);

View File

@ -27,7 +27,9 @@ abstract class KeyFrameIdBase extends KeyFrame {
}
int from = _value;
_value = value;
valueChanged(from, value);
if (hasValidated) {
valueChanged(from, value);
}
}
void valueChanged(int from, int to);

View File

@ -31,7 +31,9 @@ abstract class LinearAnimationBase extends Animation {
}
int from = _fps;
_fps = value;
fpsChanged(from, value);
if (hasValidated) {
fpsChanged(from, value);
}
}
void fpsChanged(int from, int to);
@ -53,7 +55,9 @@ abstract class LinearAnimationBase extends Animation {
}
int from = _duration;
_duration = value;
durationChanged(from, value);
if (hasValidated) {
durationChanged(from, value);
}
}
void durationChanged(int from, int to);
@ -75,7 +79,9 @@ abstract class LinearAnimationBase extends Animation {
}
double from = _speed;
_speed = value;
speedChanged(from, value);
if (hasValidated) {
speedChanged(from, value);
}
}
void speedChanged(double from, double to);
@ -97,7 +103,9 @@ abstract class LinearAnimationBase extends Animation {
}
int from = _loopValue;
_loopValue = value;
loopValueChanged(from, value);
if (hasValidated) {
loopValueChanged(from, value);
}
}
void loopValueChanged(int from, int to);
@ -119,7 +127,9 @@ abstract class LinearAnimationBase extends Animation {
}
int from = _workStart;
_workStart = value;
workStartChanged(from, value);
if (hasValidated) {
workStartChanged(from, value);
}
}
void workStartChanged(int from, int to);
@ -141,7 +151,9 @@ abstract class LinearAnimationBase extends Animation {
}
int from = _workEnd;
_workEnd = value;
workEndChanged(from, value);
if (hasValidated) {
workEndChanged(from, value);
}
}
void workEndChanged(int from, int to);
@ -164,7 +176,9 @@ abstract class LinearAnimationBase extends Animation {
}
bool from = _enableWorkArea;
_enableWorkArea = value;
enableWorkAreaChanged(from, value);
if (hasValidated) {
enableWorkAreaChanged(from, value);
}
}
void enableWorkAreaChanged(bool from, bool to);

View File

@ -32,7 +32,9 @@ abstract class StateMachineBoolBase extends StateMachineInput {
}
bool from = _value;
_value = value;
valueChanged(from, value);
if (hasValidated) {
valueChanged(from, value);
}
}
void valueChanged(bool from, bool to);

View File

@ -30,7 +30,9 @@ abstract class StateMachineComponentBase<T extends CoreContext>
}
String from = _name;
_name = value;
nameChanged(from, value);
if (hasValidated) {
nameChanged(from, value);
}
}
void nameChanged(String from, String to);

View File

@ -32,7 +32,9 @@ abstract class StateMachineDoubleBase extends StateMachineInput {
}
double from = _value;
_value = value;
valueChanged(from, value);
if (hasValidated) {
valueChanged(from, value);
}
}
void valueChanged(double from, double to);

View File

@ -30,7 +30,9 @@ abstract class StateTransitionBase extends StateMachineLayerComponent {
}
int from = _stateToId;
_stateToId = value;
stateToIdChanged(from, value);
if (hasValidated) {
stateToIdChanged(from, value);
}
}
void stateToIdChanged(int from, int to);
@ -50,7 +52,9 @@ abstract class StateTransitionBase extends StateMachineLayerComponent {
}
int from = _flags;
_flags = value;
flagsChanged(from, value);
if (hasValidated) {
flagsChanged(from, value);
}
}
void flagsChanged(int from, int to);
@ -72,7 +76,9 @@ abstract class StateTransitionBase extends StateMachineLayerComponent {
}
int from = _duration;
_duration = value;
durationChanged(from, value);
if (hasValidated) {
durationChanged(from, value);
}
}
void durationChanged(int from, int to);

View File

@ -28,7 +28,9 @@ abstract class TransitionConditionBase<T extends CoreContext> extends Core<T> {
}
int from = _inputId;
_inputId = value;
inputIdChanged(from, value);
if (hasValidated) {
inputIdChanged(from, value);
}
}
void inputIdChanged(int from, int to);

View File

@ -32,7 +32,9 @@ abstract class TransitionDoubleConditionBase extends TransitionValueCondition {
}
double from = _value;
_value = value;
valueChanged(from, value);
if (hasValidated) {
valueChanged(from, value);
}
}
void valueChanged(double from, double to);

View File

@ -30,7 +30,9 @@ abstract class TransitionValueConditionBase extends TransitionCondition {
}
int from = _opValue;
_opValue = value;
opValueChanged(from, value);
if (hasValidated) {
opValueChanged(from, value);
}
}
void opValueChanged(int from, int to);

View File

@ -33,7 +33,9 @@ abstract class ArtboardBase extends ContainerComponent {
}
double from = _width;
_width = value;
widthChanged(from, value);
if (hasValidated) {
widthChanged(from, value);
}
}
void widthChanged(double from, double to);
@ -55,7 +57,9 @@ abstract class ArtboardBase extends ContainerComponent {
}
double from = _height;
_height = value;
heightChanged(from, value);
if (hasValidated) {
heightChanged(from, value);
}
}
void heightChanged(double from, double to);
@ -77,7 +81,9 @@ abstract class ArtboardBase extends ContainerComponent {
}
double from = _x;
_x = value;
xChanged(from, value);
if (hasValidated) {
xChanged(from, value);
}
}
void xChanged(double from, double to);
@ -99,7 +105,9 @@ abstract class ArtboardBase extends ContainerComponent {
}
double from = _y;
_y = value;
yChanged(from, value);
if (hasValidated) {
yChanged(from, value);
}
}
void yChanged(double from, double to);
@ -121,7 +129,9 @@ abstract class ArtboardBase extends ContainerComponent {
}
double from = _originX;
_originX = value;
originXChanged(from, value);
if (hasValidated) {
originXChanged(from, value);
}
}
void originXChanged(double from, double to);
@ -143,7 +153,9 @@ abstract class ArtboardBase extends ContainerComponent {
}
double from = _originY;
_originY = value;
originYChanged(from, value);
if (hasValidated) {
originYChanged(from, value);
}
}
void originYChanged(double from, double to);

View File

@ -35,7 +35,9 @@ abstract class BoneBase extends SkeletalComponent {
}
double from = _length;
_length = value;
lengthChanged(from, value);
if (hasValidated) {
lengthChanged(from, value);
}
}
void lengthChanged(double from, double to);

View File

@ -28,7 +28,9 @@ abstract class CubicWeightBase extends Weight {
}
int from = _inValues;
_inValues = value;
inValuesChanged(from, value);
if (hasValidated) {
inValuesChanged(from, value);
}
}
void inValuesChanged(int from, int to);
@ -48,7 +50,9 @@ abstract class CubicWeightBase extends Weight {
}
int from = _inIndices;
_inIndices = value;
inIndicesChanged(from, value);
if (hasValidated) {
inIndicesChanged(from, value);
}
}
void inIndicesChanged(int from, int to);
@ -68,7 +72,9 @@ abstract class CubicWeightBase extends Weight {
}
int from = _outValues;
_outValues = value;
outValuesChanged(from, value);
if (hasValidated) {
outValuesChanged(from, value);
}
}
void outValuesChanged(int from, int to);
@ -88,7 +94,9 @@ abstract class CubicWeightBase extends Weight {
}
int from = _outIndices;
_outIndices = value;
outIndicesChanged(from, value);
if (hasValidated) {
outIndicesChanged(from, value);
}
}
void outIndicesChanged(int from, int to);

View File

@ -39,7 +39,9 @@ abstract class RootBoneBase extends Bone {
}
double from = _x;
_x = value;
xChanged(from, value);
if (hasValidated) {
xChanged(from, value);
}
}
void xChanged(double from, double to);
@ -61,7 +63,9 @@ abstract class RootBoneBase extends Bone {
}
double from = _y;
_y = value;
yChanged(from, value);
if (hasValidated) {
yChanged(from, value);
}
}
void yChanged(double from, double to);

View File

@ -30,7 +30,9 @@ abstract class SkinBase extends ContainerComponent {
}
double from = _xx;
_xx = value;
xxChanged(from, value);
if (hasValidated) {
xxChanged(from, value);
}
}
void xxChanged(double from, double to);
@ -52,7 +54,9 @@ abstract class SkinBase extends ContainerComponent {
}
double from = _yx;
_yx = value;
yxChanged(from, value);
if (hasValidated) {
yxChanged(from, value);
}
}
void yxChanged(double from, double to);
@ -74,7 +78,9 @@ abstract class SkinBase extends ContainerComponent {
}
double from = _xy;
_xy = value;
xyChanged(from, value);
if (hasValidated) {
xyChanged(from, value);
}
}
void xyChanged(double from, double to);
@ -96,7 +102,9 @@ abstract class SkinBase extends ContainerComponent {
}
double from = _yy;
_yy = value;
yyChanged(from, value);
if (hasValidated) {
yyChanged(from, value);
}
}
void yyChanged(double from, double to);
@ -118,7 +126,9 @@ abstract class SkinBase extends ContainerComponent {
}
double from = _tx;
_tx = value;
txChanged(from, value);
if (hasValidated) {
txChanged(from, value);
}
}
void txChanged(double from, double to);
@ -140,7 +150,9 @@ abstract class SkinBase extends ContainerComponent {
}
double from = _ty;
_ty = value;
tyChanged(from, value);
if (hasValidated) {
tyChanged(from, value);
}
}
void tyChanged(double from, double to);

View File

@ -28,7 +28,9 @@ abstract class TendonBase extends Component {
}
int from = _boneId;
_boneId = value;
boneIdChanged(from, value);
if (hasValidated) {
boneIdChanged(from, value);
}
}
void boneIdChanged(int from, int to);
@ -50,7 +52,9 @@ abstract class TendonBase extends Component {
}
double from = _xx;
_xx = value;
xxChanged(from, value);
if (hasValidated) {
xxChanged(from, value);
}
}
void xxChanged(double from, double to);
@ -72,7 +76,9 @@ abstract class TendonBase extends Component {
}
double from = _yx;
_yx = value;
yxChanged(from, value);
if (hasValidated) {
yxChanged(from, value);
}
}
void yxChanged(double from, double to);
@ -94,7 +100,9 @@ abstract class TendonBase extends Component {
}
double from = _xy;
_xy = value;
xyChanged(from, value);
if (hasValidated) {
xyChanged(from, value);
}
}
void xyChanged(double from, double to);
@ -116,7 +124,9 @@ abstract class TendonBase extends Component {
}
double from = _yy;
_yy = value;
yyChanged(from, value);
if (hasValidated) {
yyChanged(from, value);
}
}
void yyChanged(double from, double to);
@ -138,7 +148,9 @@ abstract class TendonBase extends Component {
}
double from = _tx;
_tx = value;
txChanged(from, value);
if (hasValidated) {
txChanged(from, value);
}
}
void txChanged(double from, double to);
@ -160,7 +172,9 @@ abstract class TendonBase extends Component {
}
double from = _ty;
_ty = value;
tyChanged(from, value);
if (hasValidated) {
tyChanged(from, value);
}
}
void tyChanged(double from, double to);

View File

@ -26,7 +26,9 @@ abstract class WeightBase extends Component {
}
int from = _values;
_values = value;
valuesChanged(from, value);
if (hasValidated) {
valuesChanged(from, value);
}
}
void valuesChanged(int from, int to);
@ -46,7 +48,9 @@ abstract class WeightBase extends Component {
}
int from = _indices;
_indices = value;
indicesChanged(from, value);
if (hasValidated) {
indicesChanged(from, value);
}
}
void indicesChanged(int from, int to);

View File

@ -28,7 +28,9 @@ abstract class ComponentBase<T extends CoreContext> extends Core<T> {
}
String from = _name;
_name = value;
nameChanged(from, value);
if (hasValidated) {
nameChanged(from, value);
}
}
void nameChanged(String from, String to);
@ -50,7 +52,9 @@ abstract class ComponentBase<T extends CoreContext> extends Core<T> {
}
int from = _parentId;
_parentId = value;
parentIdChanged(from, value);
if (hasValidated) {
parentIdChanged(from, value);
}
}
void parentIdChanged(int from, int to);

View File

@ -34,7 +34,9 @@ abstract class DrawRulesBase extends ContainerComponent {
}
int from = _drawTargetId;
_drawTargetId = value;
drawTargetIdChanged(from, value);
if (hasValidated) {
drawTargetIdChanged(from, value);
}
}
void drawTargetIdChanged(int from, int to);

View File

@ -28,7 +28,9 @@ abstract class DrawTargetBase extends Component {
}
int from = _drawableId;
_drawableId = value;
drawableIdChanged(from, value);
if (hasValidated) {
drawableIdChanged(from, value);
}
}
void drawableIdChanged(int from, int to);
@ -51,7 +53,9 @@ abstract class DrawTargetBase extends Component {
}
int from = _placementValue;
_placementValue = value;
placementValueChanged(from, value);
if (hasValidated) {
placementValueChanged(from, value);
}
}
void placementValueChanged(int from, int to);

View File

@ -36,7 +36,9 @@ abstract class DrawableBase extends Node {
}
int from = _blendModeValue;
_blendModeValue = value;
blendModeValueChanged(from, value);
if (hasValidated) {
blendModeValueChanged(from, value);
}
}
void blendModeValueChanged(int from, int to);
@ -57,7 +59,9 @@ abstract class DrawableBase extends Node {
}
int from = _drawableFlags;
_drawableFlags = value;
drawableFlagsChanged(from, value);
if (hasValidated) {
drawableFlagsChanged(from, value);
}
}
void drawableFlagsChanged(int from, int to);

View File

@ -35,7 +35,9 @@ abstract class NodeBase extends TransformComponent {
}
double from = _x;
_x = value;
xChanged(from, value);
if (hasValidated) {
xChanged(from, value);
}
}
void xChanged(double from, double to);
@ -57,7 +59,9 @@ abstract class NodeBase extends TransformComponent {
}
double from = _y;
_y = value;
yChanged(from, value);
if (hasValidated) {
yChanged(from, value);
}
}
void yChanged(double from, double to);

View File

@ -29,7 +29,9 @@ abstract class ClippingShapeBase extends Component {
}
int from = _sourceId;
_sourceId = value;
sourceIdChanged(from, value);
if (hasValidated) {
sourceIdChanged(from, value);
}
}
void sourceIdChanged(int from, int to);
@ -51,7 +53,9 @@ abstract class ClippingShapeBase extends Component {
}
int from = _fillRule;
_fillRule = value;
fillRuleChanged(from, value);
if (hasValidated) {
fillRuleChanged(from, value);
}
}
void fillRuleChanged(int from, int to);
@ -71,7 +75,9 @@ abstract class ClippingShapeBase extends Component {
}
bool from = _isVisible;
_isVisible = value;
isVisibleChanged(from, value);
if (hasValidated) {
isVisibleChanged(from, value);
}
}
void isVisibleChanged(bool from, bool to);

View File

@ -38,7 +38,9 @@ abstract class CubicAsymmetricVertexBase extends CubicVertex {
}
double from = _rotation;
_rotation = value;
rotationChanged(from, value);
if (hasValidated) {
rotationChanged(from, value);
}
}
void rotationChanged(double from, double to);
@ -60,7 +62,9 @@ abstract class CubicAsymmetricVertexBase extends CubicVertex {
}
double from = _inDistance;
_inDistance = value;
inDistanceChanged(from, value);
if (hasValidated) {
inDistanceChanged(from, value);
}
}
void inDistanceChanged(double from, double to);
@ -83,7 +87,9 @@ abstract class CubicAsymmetricVertexBase extends CubicVertex {
}
double from = _outDistance;
_outDistance = value;
outDistanceChanged(from, value);
if (hasValidated) {
outDistanceChanged(from, value);
}
}
void outDistanceChanged(double from, double to);

View File

@ -38,7 +38,9 @@ abstract class CubicDetachedVertexBase extends CubicVertex {
}
double from = _inRotation;
_inRotation = value;
inRotationChanged(from, value);
if (hasValidated) {
inRotationChanged(from, value);
}
}
void inRotationChanged(double from, double to);
@ -60,7 +62,9 @@ abstract class CubicDetachedVertexBase extends CubicVertex {
}
double from = _inDistance;
_inDistance = value;
inDistanceChanged(from, value);
if (hasValidated) {
inDistanceChanged(from, value);
}
}
void inDistanceChanged(double from, double to);
@ -83,7 +87,9 @@ abstract class CubicDetachedVertexBase extends CubicVertex {
}
double from = _outRotation;
_outRotation = value;
outRotationChanged(from, value);
if (hasValidated) {
outRotationChanged(from, value);
}
}
void outRotationChanged(double from, double to);
@ -106,7 +112,9 @@ abstract class CubicDetachedVertexBase extends CubicVertex {
}
double from = _outDistance;
_outDistance = value;
outDistanceChanged(from, value);
if (hasValidated) {
outDistanceChanged(from, value);
}
}
void outDistanceChanged(double from, double to);

View File

@ -38,7 +38,9 @@ abstract class CubicMirroredVertexBase extends CubicVertex {
}
double from = _rotation;
_rotation = value;
rotationChanged(from, value);
if (hasValidated) {
rotationChanged(from, value);
}
}
void rotationChanged(double from, double to);
@ -60,7 +62,9 @@ abstract class CubicMirroredVertexBase extends CubicVertex {
}
double from = _distance;
_distance = value;
distanceChanged(from, value);
if (hasValidated) {
distanceChanged(from, value);
}
}
void distanceChanged(double from, double to);

View File

@ -33,7 +33,9 @@ abstract class FillBase extends ShapePaint {
}
int from = _fillRule;
_fillRule = value;
fillRuleChanged(from, value);
if (hasValidated) {
fillRuleChanged(from, value);
}
}
void fillRuleChanged(int from, int to);

View File

@ -27,7 +27,9 @@ abstract class GradientStopBase extends Component {
}
int from = _colorValue;
_colorValue = value;
colorValueChanged(from, value);
if (hasValidated) {
colorValueChanged(from, value);
}
}
void colorValueChanged(int from, int to);
@ -47,7 +49,9 @@ abstract class GradientStopBase extends Component {
}
double from = _position;
_position = value;
positionChanged(from, value);
if (hasValidated) {
positionChanged(from, value);
}
}
void positionChanged(double from, double to);

View File

@ -32,7 +32,9 @@ abstract class LinearGradientBase extends ContainerComponent {
}
double from = _startX;
_startX = value;
startXChanged(from, value);
if (hasValidated) {
startXChanged(from, value);
}
}
void startXChanged(double from, double to);
@ -52,7 +54,9 @@ abstract class LinearGradientBase extends ContainerComponent {
}
double from = _startY;
_startY = value;
startYChanged(from, value);
if (hasValidated) {
startYChanged(from, value);
}
}
void startYChanged(double from, double to);
@ -72,7 +76,9 @@ abstract class LinearGradientBase extends ContainerComponent {
}
double from = _endX;
_endX = value;
endXChanged(from, value);
if (hasValidated) {
endXChanged(from, value);
}
}
void endXChanged(double from, double to);
@ -92,7 +98,9 @@ abstract class LinearGradientBase extends ContainerComponent {
}
double from = _endY;
_endY = value;
endYChanged(from, value);
if (hasValidated) {
endYChanged(from, value);
}
}
void endYChanged(double from, double to);
@ -112,7 +120,9 @@ abstract class LinearGradientBase extends ContainerComponent {
}
double from = _opacity;
_opacity = value;
opacityChanged(from, value);
if (hasValidated) {
opacityChanged(from, value);
}
}
void opacityChanged(double from, double to);

View File

@ -32,7 +32,9 @@ abstract class ShapePaintBase extends ContainerComponent {
}
bool from = _isVisible;
_isVisible = value;
isVisibleChanged(from, value);
if (hasValidated) {
isVisibleChanged(from, value);
}
}
void isVisibleChanged(bool from, bool to);

View File

@ -27,7 +27,9 @@ abstract class SolidColorBase extends Component {
}
int from = _colorValue;
_colorValue = value;
colorValueChanged(from, value);
if (hasValidated) {
colorValueChanged(from, value);
}
}
void colorValueChanged(int from, int to);

View File

@ -34,7 +34,9 @@ abstract class StrokeBase extends ShapePaint {
}
double from = _thickness;
_thickness = value;
thicknessChanged(from, value);
if (hasValidated) {
thicknessChanged(from, value);
}
}
void thicknessChanged(double from, double to);
@ -54,7 +56,9 @@ abstract class StrokeBase extends ShapePaint {
}
int from = _cap;
_cap = value;
capChanged(from, value);
if (hasValidated) {
capChanged(from, value);
}
}
void capChanged(int from, int to);
@ -74,7 +78,9 @@ abstract class StrokeBase extends ShapePaint {
}
int from = _join;
_join = value;
joinChanged(from, value);
if (hasValidated) {
joinChanged(from, value);
}
}
void joinChanged(int from, int to);
@ -95,7 +101,9 @@ abstract class StrokeBase extends ShapePaint {
}
bool from = _transformAffectsStroke;
_transformAffectsStroke = value;
transformAffectsStrokeChanged(from, value);
if (hasValidated) {
transformAffectsStrokeChanged(from, value);
}
}
void transformAffectsStrokeChanged(bool from, bool to);

View File

@ -27,7 +27,9 @@ abstract class TrimPathBase extends Component {
}
double from = _start;
_start = value;
startChanged(from, value);
if (hasValidated) {
startChanged(from, value);
}
}
void startChanged(double from, double to);
@ -47,7 +49,9 @@ abstract class TrimPathBase extends Component {
}
double from = _end;
_end = value;
endChanged(from, value);
if (hasValidated) {
endChanged(from, value);
}
}
void endChanged(double from, double to);
@ -67,7 +71,9 @@ abstract class TrimPathBase extends Component {
}
double from = _offset;
_offset = value;
offsetChanged(from, value);
if (hasValidated) {
offsetChanged(from, value);
}
}
void offsetChanged(double from, double to);
@ -87,7 +93,9 @@ abstract class TrimPathBase extends Component {
}
int from = _modeValue;
_modeValue = value;
modeValueChanged(from, value);
if (hasValidated) {
modeValueChanged(from, value);
}
}
void modeValueChanged(int from, int to);

View File

@ -40,7 +40,9 @@ abstract class ParametricPathBase extends Path {
}
double from = _width;
_width = value;
widthChanged(from, value);
if (hasValidated) {
widthChanged(from, value);
}
}
void widthChanged(double from, double to);
@ -62,7 +64,9 @@ abstract class ParametricPathBase extends Path {
}
double from = _height;
_height = value;
heightChanged(from, value);
if (hasValidated) {
heightChanged(from, value);
}
}
void heightChanged(double from, double to);
@ -84,7 +88,9 @@ abstract class ParametricPathBase extends Path {
}
double from = _originX;
_originX = value;
originXChanged(from, value);
if (hasValidated) {
originXChanged(from, value);
}
}
void originXChanged(double from, double to);
@ -106,7 +112,9 @@ abstract class ParametricPathBase extends Path {
}
double from = _originY;
_originY = value;
originYChanged(from, value);
if (hasValidated) {
originYChanged(from, value);
}
}
void originYChanged(double from, double to);

View File

@ -35,7 +35,9 @@ abstract class PathBase extends Node {
}
int from = _pathFlags;
_pathFlags = value;
pathFlagsChanged(from, value);
if (hasValidated) {
pathFlagsChanged(from, value);
}
}
void pathFlagsChanged(int from, int to);

View File

@ -33,7 +33,9 @@ abstract class PathVertexBase extends ContainerComponent {
}
double from = _x;
_x = value;
xChanged(from, value);
if (hasValidated) {
xChanged(from, value);
}
}
void xChanged(double from, double to);
@ -55,7 +57,9 @@ abstract class PathVertexBase extends ContainerComponent {
}
double from = _y;
_y = value;
yChanged(from, value);
if (hasValidated) {
yChanged(from, value);
}
}
void yChanged(double from, double to);

View File

@ -40,7 +40,9 @@ abstract class PointsPathBase extends Path {
}
bool from = _isClosed;
_isClosed = value;
isClosedChanged(from, value);
if (hasValidated) {
isClosedChanged(from, value);
}
}
void isClosedChanged(bool from, bool to);

View File

@ -41,7 +41,9 @@ abstract class PolygonBase extends ParametricPath {
}
int from = _points;
_points = value;
pointsChanged(from, value);
if (hasValidated) {
pointsChanged(from, value);
}
}
void pointsChanged(int from, int to);
@ -64,7 +66,9 @@ abstract class PolygonBase extends ParametricPath {
}
double from = _cornerRadius;
_cornerRadius = value;
cornerRadiusChanged(from, value);
if (hasValidated) {
cornerRadiusChanged(from, value);
}
}
void cornerRadiusChanged(double from, double to);

View File

@ -42,7 +42,9 @@ abstract class RectangleBase extends ParametricPath {
}
double from = _cornerRadius;
_cornerRadius = value;
cornerRadiusChanged(from, value);
if (hasValidated) {
cornerRadiusChanged(from, value);
}
}
void cornerRadiusChanged(double from, double to);

View File

@ -44,7 +44,9 @@ abstract class StarBase extends Polygon {
}
double from = _innerRadius;
_innerRadius = value;
innerRadiusChanged(from, value);
if (hasValidated) {
innerRadiusChanged(from, value);
}
}
void innerRadiusChanged(double from, double to);

View File

@ -37,7 +37,9 @@ abstract class StraightVertexBase extends PathVertex<Weight> {
}
double from = _radius;
_radius = value;
radiusChanged(from, value);
if (hasValidated) {
radiusChanged(from, value);
}
}
void radiusChanged(double from, double to);

View File

@ -32,7 +32,9 @@ abstract class TransformComponentBase extends ContainerComponent {
}
double from = _rotation;
_rotation = value;
rotationChanged(from, value);
if (hasValidated) {
rotationChanged(from, value);
}
}
void rotationChanged(double from, double to);
@ -52,7 +54,9 @@ abstract class TransformComponentBase extends ContainerComponent {
}
double from = _scaleX;
_scaleX = value;
scaleXChanged(from, value);
if (hasValidated) {
scaleXChanged(from, value);
}
}
void scaleXChanged(double from, double to);
@ -72,7 +76,9 @@ abstract class TransformComponentBase extends ContainerComponent {
}
double from = _scaleY;
_scaleY = value;
scaleYChanged(from, value);
if (hasValidated) {
scaleYChanged(from, value);
}
}
void scaleYChanged(double from, double to);
@ -92,7 +98,9 @@ abstract class TransformComponentBase extends ContainerComponent {
}
double from = _opacity;
_opacity = value;
opacityChanged(from, value);
if (hasValidated) {
opacityChanged(from, value);
}
}
void opacityChanged(double from, double to);

View File

@ -39,8 +39,7 @@ class Rive extends LeafRenderObjectWidget {
@override
RenderObject createRenderObject(BuildContext context) {
return RiveRenderObject()
..artboard = artboard
return RiveRenderObject(artboard as RuntimeArtboard)
..fit = fit
..alignment = alignment
..artboardSize = Size(artboard.width, artboard.height)
@ -65,7 +64,10 @@ class Rive extends LeafRenderObjectWidget {
}
class RiveRenderObject extends RiveRenderBox {
late RuntimeArtboard _artboard;
RuntimeArtboard _artboard;
RiveRenderObject(this._artboard) {
_artboard.redraw.addListener(scheduleRepaint);
}
RuntimeArtboard get artboard => _artboard;

View File

@ -4,15 +4,15 @@ import 'package:rive/src/generated/animation/animation_base.dart';
export 'package:rive/src/generated/animation/animation_base.dart';
class Animation extends AnimationBase<RuntimeArtboard> {
late Artboard _artboard;
Artboard get artboard => _artboard;
set artboard(Artboard value) {
Artboard? _artboard;
Artboard? get artboard => _artboard;
set artboard(Artboard? value) {
if (_artboard == value) {
return;
}
_artboard.internalRemoveAnimation(this);
_artboard?.internalRemoveAnimation(this);
_artboard = value;
_artboard.internalAddAnimation(this);
_artboard?.internalAddAnimation(this);
}
@override
@ -20,5 +20,7 @@ class Animation extends AnimationBase<RuntimeArtboard> {
@override
void onAdded() {}
@override
bool validate() => super.validate() && _artboard != null;
@override
void nameChanged(String from, String to) {}
}

View File

@ -15,10 +15,7 @@ import 'package:rive/src/utilities/dependency_sorter.dart';
import 'package:rive/src/generated/artboard_base.dart';
export 'package:rive/src/generated/artboard_base.dart';
class _UnknownArtboard extends Artboard {}
class Artboard extends ArtboardBase with ShapePaintContainer {
static final Artboard unknown = _UnknownArtboard();
@override
bool get canBeOrphaned => true;
final Path path = Path();
@ -173,7 +170,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
fill.draw(canvas, path);
}
for (var drawable = _firstDrawable;
drawable != Drawable.unknown;
drawable != null;
drawable = drawable.prev) {
if (drawable.isHidden) {
continue;
@ -240,7 +237,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
void onStrokesChanged() {}
@override
Vec2D get worldTranslation => Vec2D();
Drawable _firstDrawable = Drawable.unknown;
Drawable? _firstDrawable;
void computeDrawOrder() {
_drawables.clear();
_rules.clear();
@ -254,7 +251,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
for (final nodeRules in _rules) {
for (final target in nodeRules.targets) {
root.dependents.add(target);
var dependentRules = target.drawable.flattenedDrawRules;
var dependentRules = target.drawable?.flattenedDrawRules;
if (dependentRules != null) {
for (final dependentRule in dependentRules.targets) {
dependentRule.dependents.add(target);
@ -269,27 +266,27 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
void sortDrawOrder() {
for (final rule in _sortedDrawRules) {
rule.first = rule.last = Drawable.unknown;
rule.first = rule.last = null;
}
_firstDrawable = Drawable.unknown;
Drawable lastDrawable = Drawable.unknown;
_firstDrawable = null;
Drawable? lastDrawable;
for (final drawable in _drawables) {
var rules = drawable.flattenedDrawRules;
var target = rules?.activeTarget;
if (target != null) {
if (target.first == Drawable.unknown) {
if (target.first == null) {
target.first = target.last = drawable;
drawable.prev = drawable.next = Drawable.unknown;
drawable.prev = drawable.next = null;
} else {
target.last.next = drawable;
target.last?.next = drawable;
drawable.prev = target.last;
target.last = drawable;
drawable.next = Drawable.unknown;
drawable.next = null;
}
} else {
drawable.prev = lastDrawable;
drawable.next = Drawable.unknown;
if (lastDrawable == Drawable.unknown) {
drawable.next = null;
if (lastDrawable == null) {
lastDrawable = _firstDrawable = drawable;
} else {
lastDrawable.next = drawable;
@ -298,31 +295,31 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
}
}
for (final rule in _sortedDrawRules) {
if (rule.first == Drawable.unknown) {
if (rule.first == null) {
continue;
}
switch (rule.placement) {
case DrawTargetPlacement.before:
if (rule.drawable.prev != Drawable.unknown) {
rule.drawable.prev.next = rule.first;
rule.first.prev = rule.drawable.prev;
if (rule.drawable?.prev != null) {
rule.drawable!.prev?.next = rule.first;
rule.first?.prev = rule.drawable!.prev;
}
if (rule.drawable == _firstDrawable) {
_firstDrawable = rule.first;
}
rule.drawable.prev = rule.last;
rule.last.next = rule.drawable;
rule.drawable?.prev = rule.last;
rule.last?.next = rule.drawable;
break;
case DrawTargetPlacement.after:
if (rule.drawable.next != Drawable.unknown) {
rule.drawable.next.prev = rule.last;
rule.last.next = rule.drawable.next;
if (rule.drawable?.next != null) {
rule.drawable!.next!.prev = rule.last;
rule.last?.next = rule.drawable?.next;
}
if (rule.drawable == lastDrawable) {
lastDrawable = rule.last;
}
rule.drawable.next = rule.first;
rule.first.prev = rule.drawable;
rule.drawable?.next = rule.first;
rule.first?.prev = rule.drawable;
break;
}
}

View File

@ -54,7 +54,7 @@ class Skin extends SkinBase {
super.onAddedDirty();
if (parent is Skinnable) {
(parent as Skinnable).addSkin(this);
parent.markRebuildDependencies();
parent!.markRebuildDependencies();
}
}
@ -62,7 +62,7 @@ class Skin extends SkinBase {
void onRemoved() {
if (parent is Skinnable) {
(parent as Skinnable).removeSkin(this);
parent.markRebuildDependencies();
parent!.markRebuildDependencies();
}
super.onRemoved();
}
@ -82,7 +82,7 @@ class Skin extends SkinBase {
case TendonBase.typeKey:
_tendons.add(child as Tendon);
markRebuildDependencies();
parent.markRebuildDependencies();
parent!.markRebuildDependencies();
break;
}
}
@ -98,7 +98,7 @@ class Skin extends SkinBase {
} else {
markRebuildDependencies();
}
parent.markRebuildDependencies();
parent!.markRebuildDependencies();
break;
}
}

View File

@ -9,7 +9,7 @@ export 'package:rive/src/generated/component_base.dart';
abstract class Component extends ComponentBase<RuntimeArtboard>
implements DependencyGraphNode<Component>, Parentable<Component> {
Artboard _artboard = Artboard.unknown;
Artboard? _artboard;
dynamic _userData;
bool get canBeOrphaned => false;
int graphOrder = 0;
@ -21,7 +21,7 @@ abstract class Component extends ComponentBase<RuntimeArtboard>
}
dirt |= value;
onDirty(dirt);
artboard.onComponentDirty(this);
artboard?.onComponentDirty(this);
if (!recurse) {
return true;
}
@ -33,22 +33,22 @@ abstract class Component extends ComponentBase<RuntimeArtboard>
void onDirty(int mask) {}
void update(int dirt);
Artboard get artboard => _artboard;
void _changeArtboard(Artboard value) {
Artboard? get artboard => _artboard;
void _changeArtboard(Artboard? value) {
if (_artboard == value) {
return;
}
_artboard.removeComponent(this);
_artboard?.removeComponent(this);
_artboard = value;
_artboard.addComponent(this);
_artboard?.addComponent(this);
}
@mustCallSuper
void visitAncestor(Component ancestor) {}
bool resolveArtboard() {
int sanity = maxTreeDepth;
for (Component curr = this;
curr != ContainerComponent.unknown && sanity > 0;
for (Component? curr = this;
curr != null && sanity > 0;
curr = curr.parent, sanity--) {
visitAncestor(curr);
if (curr is Artboard) {
@ -56,7 +56,7 @@ abstract class Component extends ComponentBase<RuntimeArtboard>
return true;
}
}
_changeArtboard(Artboard.unknown);
_changeArtboard(null);
return false;
}
@ -72,27 +72,29 @@ abstract class Component extends ComponentBase<RuntimeArtboard>
void userDataChanged(dynamic from, dynamic to) {}
@override
void parentIdChanged(int from, int to) =>
parent = context.resolveWithDefault(to, ContainerComponent.unknown);
ContainerComponent _parent = ContainerComponent.unknown;
void parentIdChanged(int from, int to) {
parent = context.resolve(to);
}
ContainerComponent? _parent;
@override
ContainerComponent get parent => _parent;
set parent(ContainerComponent value) {
ContainerComponent? get parent => _parent;
set parent(ContainerComponent? value) {
if (_parent == value) {
return;
}
var old = _parent;
_parent = value;
parentId = value.id;
parentId = value?.id ?? Core.missingId;
parentChanged(old, value);
}
@protected
void parentChanged(ContainerComponent from, ContainerComponent to) {
from.children.remove(this);
from.childRemoved(this);
to.children.add(this);
to.childAdded(this);
void parentChanged(ContainerComponent? from, ContainerComponent? to) {
from?.children.remove(this);
from?.childRemoved(this);
to?.children.add(this);
to?.childAdded(this);
markRebuildDependencies();
}
@ -133,7 +135,7 @@ abstract class Component extends ComponentBase<RuntimeArtboard>
void onAdded() {}
@override
void onAddedDirty() {
parent = context.resolveWithDefault(parentId, ContainerComponent.unknown);
parent = context.resolve(parentId);
}
@override
@ -148,12 +150,14 @@ abstract class Component extends ComponentBase<RuntimeArtboard>
dependent.onDependencyRemoved(this);
}
_dependents.clear();
if (parent != ContainerComponent.unknown) {
parent.children.remove(this);
parent.childRemoved(this);
if (parent != null) {
parent!.children.remove(this);
parent!.childRemoved(this);
}
if (artboard != null) {
context.markDependencyOrderDirty();
_changeArtboard(null);
}
context.markDependencyOrderDirty();
_changeArtboard(Artboard.unknown);
}
@override

View File

@ -7,15 +7,8 @@ import 'package:rive/src/generated/container_component_base.dart';
typedef bool DescentCallback(Component component);
class _UnknownParent extends ContainerComponent {
@override
void update(int dirt) => throw UnsupportedError(
'Something is incorrectly referencing an unknown parent');
}
abstract class ContainerComponent extends ContainerComponentBase {
final ContainerChildren children = ContainerChildren();
static final unknown = _UnknownParent();
void appendChild(Component child) {
child.parent = this;
}

View File

@ -14,7 +14,7 @@ class DrawRules extends DrawRulesBase {
@override
void drawTargetIdChanged(int from, int to) {
_activeTarget = context.resolve(to);
artboard.markDrawOrderDirty();
artboard?.markDrawOrderDirty();
}
@override

View File

@ -1,3 +1,4 @@
import 'package:rive/src/core/core.dart';
import 'package:rive/src/rive_core/drawable.dart';
import 'package:rive/src/generated/draw_target_base.dart';
export 'package:rive/src/generated/draw_target_base.dart';
@ -5,16 +6,16 @@ export 'package:rive/src/generated/draw_target_base.dart';
enum DrawTargetPlacement { before, after }
class DrawTarget extends DrawTargetBase {
Drawable first = Drawable.unknown;
Drawable last = Drawable.unknown;
Drawable _drawable = Drawable.unknown;
Drawable get drawable => _drawable;
set drawable(Drawable value) {
Drawable? first;
Drawable? last;
Drawable? _drawable;
Drawable? get drawable => _drawable;
set drawable(Drawable? value) {
if (_drawable == value) {
return;
}
_drawable = value;
drawableId = value.id;
drawableId = value?.id ?? Core.missingId;
}
DrawTargetPlacement get placement =>
@ -22,18 +23,18 @@ class DrawTarget extends DrawTargetBase {
set placement(DrawTargetPlacement value) => placementValue = value.index;
@override
void drawableIdChanged(int from, int to) {
drawable = context.resolveWithDefault(to, Drawable.unknown);
drawable = context.resolve(to);
}
@override
void onAddedDirty() {
super.onAddedDirty();
drawable = context.resolveWithDefault(drawableId, Drawable.unknown);
drawable = context.resolve(drawableId);
}
@override
void placementValueChanged(int from, int to) {
artboard.markDrawOrderDirty();
artboard?.markDrawOrderDirty();
}
@override

View File

@ -8,17 +8,10 @@ import 'package:rive/src/generated/drawable_base.dart';
import 'package:rive/src/rive_core/transform_component.dart';
export 'package:rive/src/generated/drawable_base.dart';
class _UnknownDrawable extends Drawable {
@override
void draw(Canvas canvas) =>
throw UnsupportedError('Cannot draw an unknown drawable.');
}
abstract class Drawable extends DrawableBase {
static final Drawable unknown = _UnknownDrawable();
DrawRules? flattenedDrawRules;
Drawable prev = Drawable.unknown;
Drawable next = Drawable.unknown;
Drawable? prev;
Drawable? next;
@override
void buildDrawOrder(
List<Drawable> drawables, DrawRules? rules, List<DrawRules> allRules) {
@ -48,7 +41,7 @@ abstract class Drawable extends DrawableBase {
}
@override
void parentChanged(ContainerComponent from, ContainerComponent to) {
void parentChanged(ContainerComponent? from, ContainerComponent? to) {
super.parentChanged(from, to);
addDirt(ComponentDirt.clip);
}
@ -58,9 +51,7 @@ abstract class Drawable extends DrawableBase {
super.update(dirt);
if (dirt & ComponentDirt.clip != 0) {
List<ClippingShape> clippingShapes = [];
for (ContainerComponent p = this;
p != ContainerComponent.unknown;
p = p.parent) {
for (ContainerComponent? p = this; p != null; p = p.parent) {
if (p is TransformComponent) {
if (p.clippingShapes.isNotEmpty) {
clippingShapes.addAll(p.clippingShapes);

View File

@ -22,13 +22,15 @@ class ClippingShape extends ClippingShapeBase {
@override
void fillRuleChanged(int from, int to) {
parent.addDirt(ComponentDirt.clip, recurse: true);
parent?.addDirt(ComponentDirt.clip, recurse: true);
addDirt(ComponentDirt.path);
}
@override
void sourceIdChanged(int from, int to) =>
source = context.resolveWithDefault(to, Node.unknown);
void sourceIdChanged(int from, int to) {
source = context.resolveWithDefault(to, Node.unknown);
}
@override
void onAddedDirty() {
super.onAddedDirty();

View File

@ -57,20 +57,20 @@ class CubicAsymmetricVertex extends CubicAsymmetricVertexBase {
void inDistanceChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_inPoint = _outPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
@override
void outDistanceChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_inPoint = _outPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
@override
void rotationChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_inPoint = _outPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
}

View File

@ -67,27 +67,27 @@ class CubicDetachedVertex extends CubicDetachedVertexBase {
void inDistanceChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_inPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
@override
void inRotationChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_inPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
@override
void outDistanceChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_outPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
@override
void outRotationChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_outPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
}

View File

@ -52,13 +52,13 @@ class CubicMirroredVertex extends CubicMirroredVertexBase {
void distanceChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_inPoint = _outPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
@override
void rotationChanged(double from, double to) {
addDirt(ComponentDirt.worldTransform);
_inPoint = _outPoint = null;
path.markPathDirty();
path?.markPathDirty();
}
}

View File

@ -10,7 +10,8 @@ class Fill extends FillBase {
PathFillType get fillType => PathFillType.values[fillRule];
set fillType(PathFillType type) => fillRule = type.index;
@override
void fillRuleChanged(int from, int to) => parent.addDirt(ComponentDirt.paint);
void fillRuleChanged(int from, int to) =>
parent?.addDirt(ComponentDirt.paint);
@override
void update(int dirt) {}
@override

View File

@ -5,8 +5,8 @@ import 'package:rive/src/rive_core/shapes/paint/linear_gradient.dart';
export 'package:rive/src/generated/shapes/paint/gradient_stop_base.dart';
class GradientStop extends GradientStopBase {
LinearGradient _gradient = LinearGradient.unknown;
LinearGradient get gradient => _gradient;
LinearGradient? _gradient;
LinearGradient? get gradient => _gradient;
ui.Color get color => ui.Color(colorValue);
set color(ui.Color c) {
colorValue = c.value;
@ -14,23 +14,25 @@ class GradientStop extends GradientStopBase {
@override
void positionChanged(double from, double to) {
_gradient.markStopsDirty();
_gradient?.markStopsDirty();
}
@override
void colorValueChanged(int from, int to) {
_gradient.markGradientDirty();
_gradient?.markGradientDirty();
}
@override
void update(int dirt) {}
@override
void parentChanged(ContainerComponent from, ContainerComponent to) {
bool validate() => super.validate() && _gradient != null;
@override
void parentChanged(ContainerComponent? from, ContainerComponent? to) {
super.parentChanged(from, to);
if (parent is LinearGradient) {
_gradient = parent as LinearGradient;
} else {
_gradient = LinearGradient.unknown;
_gradient = null;
}
}
}

View File

@ -8,11 +8,8 @@ import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart';
import 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart';
export 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart';
class _UnknownGradient extends LinearGradient {}
class LinearGradient extends LinearGradientBase with ShapePaintMutator {
final List<GradientStop> gradientStops = [];
static final LinearGradient unknown = _UnknownGradient();
bool _paintsInWorldSpace = true;
bool get paintsInWorldSpace => _paintsInWorldSpace;
set paintsInWorldSpace(bool value) {
@ -30,7 +27,7 @@ class LinearGradient extends LinearGradientBase with ShapePaintMutator {
@override
void buildDependencies() {
super.buildDependencies();
shapePaintContainer.addDependent(this);
shapePaintContainer?.addDependent(this);
}
@override
@ -72,7 +69,7 @@ class LinearGradient extends LinearGradientBase with ShapePaintMutator {
colorPositions.add(stop.position);
}
if (paintsInWorldSpace) {
var world = shapePaintContainer.worldTransform;
var world = shapePaintContainer!.worldTransform;
var worldStart = Vec2D.transformMat2D(Vec2D(), start, world);
var worldEnd = Vec2D.transformMat2D(Vec2D(), end, world);
paint.shader = makeGradient(ui.Offset(worldStart[0], worldStart[1]),
@ -111,7 +108,7 @@ class LinearGradient extends LinearGradientBase with ShapePaintMutator {
@override
void opacityChanged(double from, double to) {
syncColor();
shapePaintContainer.addDirt(ComponentDirt.paint);
shapePaintContainer!.addDirt(ComponentDirt.paint);
}
@override
@ -119,4 +116,7 @@ class LinearGradient extends LinearGradientBase with ShapePaintMutator {
paint.color = const ui.Color(0xFFFFFFFF)
.withOpacity((opacity * renderOpacity).clamp(0, 1).toDouble());
}
@override
bool validate() => super.validate() && shapePaintContainer != null;
}

View File

@ -10,17 +10,18 @@ export 'package:rive/src/generated/shapes/paint/shape_paint_base.dart';
abstract class ShapePaint extends ShapePaintBase {
late Paint _paint;
Paint get paint => _paint;
ShapePaintMutator _paintMutator = ShapePaintMutator.unknown;
ShapePaintContainer get shapePaintContainer => parent as ShapePaintContainer;
ShapePaintMutator? _paintMutator;
ShapePaintContainer? get shapePaintContainer =>
parent as ShapePaintContainer?;
ShapePaint() {
_paint = makePaint();
}
BlendMode get blendMode => _paint.blendMode;
set blendMode(BlendMode value) => _paint.blendMode = value;
double get renderOpacity => _paintMutator.renderOpacity;
set renderOpacity(double value) => _paintMutator.renderOpacity = value;
ShapePaintMutator get paintMutator => _paintMutator;
void _changeMutator(ShapePaintMutator mutator) {
double get renderOpacity => _paintMutator!.renderOpacity;
set renderOpacity(double value) => _paintMutator!.renderOpacity = value;
ShapePaintMutator? get paintMutator => _paintMutator;
void _changeMutator(ShapePaintMutator? mutator) {
_paint = makePaint();
_paintMutator = mutator;
}
@ -40,12 +41,10 @@ abstract class ShapePaint extends ShapePaintBase {
bool validate() =>
super.validate() &&
parent is ShapePaintContainer &&
_paintMutator != ShapePaintMutator.unknown;
_paintMutator != null;
@override
void isVisibleChanged(bool from, bool to) {
if (hasValidated) {
shapePaintContainer.addDirt(ComponentDirt.paint);
}
shapePaintContainer?.addDirt(ComponentDirt.paint);
}
@override
@ -53,15 +52,11 @@ abstract class ShapePaint extends ShapePaintBase {
super.childRemoved(child);
if (child is ShapePaintMutator &&
_paintMutator == child as ShapePaintMutator) {
_changeMutator(ShapePaintMutator.unknown);
}
}
void _initMutator() {
if (hasValidated) {
_paintMutator.initializePaintMutator(shapePaintContainer, paint);
_changeMutator(null);
}
}
void _initMutator() =>
_paintMutator?.initializePaintMutator(shapePaintContainer!, paint);
void draw(Canvas canvas, Path path);
}

View File

@ -2,19 +2,10 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:rive/src/rive_core/shapes/shape_paint_container.dart';
class _UnknownMutator extends ShapePaintMutator {
@override
void syncColor() {
throw UnsupportedError(
'Not expected to call sync color on an UnknownMutator.');
}
}
abstract class ShapePaintMutator {
ShapePaintContainer _shapePaintContainer = ShapePaintContainer.unknown;
ShapePaintContainer? _shapePaintContainer;
late Paint _paint;
static final ShapePaintMutator unknown = _UnknownMutator();
ShapePaintContainer get shapePaintContainer => _shapePaintContainer;
ShapePaintContainer? get shapePaintContainer => _shapePaintContainer;
Paint get paint => _paint;
double _renderOpacity = 1;
double get renderOpacity => _renderOpacity;
@ -31,7 +22,7 @@ abstract class ShapePaintMutator {
void initializePaintMutator(ShapePaintContainer container, Paint paint) {
_shapePaintContainer = container;
_paint = paint;
_shapePaintContainer.onPaintMutatorChanged(this);
_shapePaintContainer?.onPaintMutatorChanged(this);
syncColor();
}
}

View File

@ -1,5 +1,6 @@
import 'dart:ui';
import 'package:rive/src/rive_core/component_dirt.dart';
import 'package:rive/src/rive_core/shapes/paint/shape_paint.dart';
import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart';
import 'package:rive/src/rive_core/shapes/shape_paint_container.dart';
import 'package:rive/src/generated/shapes/paint/solid_color_base.dart';
@ -14,7 +15,7 @@ class SolidColor extends SolidColorBase with ShapePaintMutator {
@override
void colorValueChanged(int from, int to) {
syncColor();
shapePaintContainer.addDirt(ComponentDirt.paint);
shapePaintContainer?.addDirt(ComponentDirt.paint);
}
@override
@ -30,4 +31,7 @@ class SolidColor extends SolidColorBase with ShapePaintMutator {
paint.color = color
.withOpacity((color.opacity * renderOpacity).clamp(0, 1).toDouble());
}
@override
bool validate() => super.validate() && parent is ShapePaint;
}

View File

@ -33,19 +33,19 @@ class Stroke extends StrokeBase {
@override
void capChanged(int from, int to) {
paint.strokeCap = StrokeCap.values[to];
parent.addDirt(ComponentDirt.paint);
parent?.addDirt(ComponentDirt.paint);
}
@override
void joinChanged(int from, int to) {
paint.strokeJoin = StrokeJoin.values[to];
parent.addDirt(ComponentDirt.paint);
parent?.addDirt(ComponentDirt.paint);
}
@override
void thicknessChanged(double from, double to) {
paint.strokeWidth = to;
parent.addDirt(ComponentDirt.paint);
parent?.addDirt(ComponentDirt.paint);
}
@override

View File

@ -48,13 +48,13 @@ class TrimPath extends TrimPathBase implements StrokeEffect {
return _renderPath = _trimmedPath;
}
Stroke get stroke => parent as Stroke;
Stroke? get stroke => parent as Stroke?;
TrimPathMode get mode => TrimPathMode.values[modeValue];
set mode(TrimPathMode value) => modeValue = value.index;
@override
void invalidateEffect() {
_renderPath = null;
stroke.shapePaintContainer.addDirt(ComponentDirt.paint);
stroke?.shapePaintContainer?.addDirt(ComponentDirt.paint);
}
@override
@ -70,13 +70,13 @@ class TrimPath extends TrimPathBase implements StrokeEffect {
@override
void onAdded() {
super.onAdded();
stroke.addStrokeEffect(this);
stroke?.addStrokeEffect(this);
_renderPath = null;
}
@override
void onRemoved() {
stroke.removeStrokeEffect(this);
stroke?.removeStrokeEffect(this);
super.onRemoved();
}
}

View File

@ -16,31 +16,31 @@ abstract class ParametricPath extends ParametricPathBase {
@override
void xChanged(double from, double to) {
super.xChanged(from, to);
shape.pathChanged(this);
shape?.pathChanged(this);
}
@override
void yChanged(double from, double to) {
super.yChanged(from, to);
shape.pathChanged(this);
shape?.pathChanged(this);
}
@override
void rotationChanged(double from, double to) {
super.rotationChanged(from, to);
shape.pathChanged(this);
shape?.pathChanged(this);
}
@override
void scaleXChanged(double from, double to) {
super.scaleXChanged(from, to);
shape.pathChanged(this);
shape?.pathChanged(this);
}
@override
void scaleYChanged(double from, double to) {
super.scaleYChanged(from, to);
shape.pathChanged(this);
shape?.pathChanged(this);
}
@override

View File

@ -25,44 +25,44 @@ abstract class Path extends PathBase {
bool _isValid = false;
bool get isClosed;
Shape _shape = Shape.unknown;
Shape get shape => _shape;
Shape? _shape;
Shape? get shape => _shape;
Mat2D get pathTransform;
Mat2D get inversePathTransform;
Mat2D get inverseWorldTransform => _inverseWorldTransform;
@override
bool resolveArtboard() {
_changeShape(Shape.unknown);
_changeShape(null);
return super.resolveArtboard();
}
@override
void visitAncestor(Component ancestor) {
super.visitAncestor(ancestor);
if (_shape != Shape.unknown && ancestor is Shape) {
if (_shape != null && ancestor is Shape) {
_changeShape(ancestor);
}
}
void _changeShape(Shape value) {
void _changeShape(Shape? value) {
if (_shape == value) {
return;
}
_shape.removePath(this);
value.addPath(this);
_shape?.removePath(this);
value?.addPath(this);
_shape = value;
}
@override
void onRemoved() {
_changeShape(Shape.unknown);
_changeShape(null);
super.onRemoved();
}
@override
void updateWorldTransform() {
super.updateWorldTransform();
_shape.pathChanged(this);
_shape?.pathChanged(this);
if (!Mat2D.invert(_inverseWorldTransform, pathTransform)) {
Mat2D.setIdentity(_inverseWorldTransform);
}
@ -79,7 +79,7 @@ abstract class Path extends PathBase {
void markPathDirty() {
addDirt(ComponentDirt.path);
_isValid = false;
_shape.pathChanged(this);
_shape?.pathChanged(this);
}
List<PathVertex> get vertices;

View File

@ -7,32 +7,33 @@ import 'package:rive/src/generated/shapes/path_composer_base.dart';
class PathComposer extends PathComposerBase {
static final PathComposer unknown = PathComposer();
Shape _shape = Shape.unknown;
Shape get shape => _shape;
Shape? _shape;
Shape? get shape => _shape;
final ui.Path worldPath = ui.Path();
final ui.Path localPath = ui.Path();
ui.Path _fillPath = ui.Path();
ui.Path get fillPath => _fillPath;
void _changeShape(Shape value) {
void _changeShape(Shape? value) {
if (value == _shape) {
return;
}
if (_shape != Shape.unknown && _shape.pathComposer == this) {
_shape.pathComposer = PathComposer.unknown;
if (_shape != null && _shape!.pathComposer == this) {
_shape!.pathComposer = PathComposer.unknown;
}
value.pathComposer = this;
value?.pathComposer = this;
_shape = value;
}
void _recomputePath() {
var buildLocalPath = _shape.wantLocalPath;
var buildWorldPath = _shape.wantWorldPath || !buildLocalPath;
assert(_shape != null);
var buildLocalPath = _shape!.wantLocalPath;
var buildWorldPath = _shape!.wantWorldPath || !buildLocalPath;
if (buildLocalPath) {
localPath.reset();
var world = _shape.worldTransform;
var world = _shape!.worldTransform;
Mat2D inverseWorld = Mat2D();
if (Mat2D.invert(inverseWorld, world)) {
for (final path in _shape.paths) {
for (final path in _shape!.paths) {
if (path.isHidden) {
continue;
}
@ -45,7 +46,7 @@ class PathComposer extends PathComposerBase {
}
if (buildWorldPath) {
worldPath.reset();
for (final path in _shape.paths) {
for (final path in _shape!.paths) {
if (path.isHidden) {
continue;
}
@ -53,14 +54,15 @@ class PathComposer extends PathComposerBase {
matrix4: path.pathTransform.mat4);
}
}
_fillPath = _shape.fillInWorld ? worldPath : localPath;
_fillPath = _shape!.fillInWorld ? worldPath : localPath;
}
@override
void buildDependencies() {
assert(_shape != null);
super.buildDependencies();
_shape.addDependent(this);
for (final path in _shape.paths) {
_shape!.addDependent(this);
for (final path in _shape!.paths) {
path.addDependent(this);
}
}
@ -74,14 +76,14 @@ class PathComposer extends PathComposerBase {
@override
bool resolveArtboard() {
_changeShape(Shape.unknown);
_changeShape(null);
return super.resolveArtboard();
}
@override
void visitAncestor(Component ancestor) {
super.visitAncestor(ancestor);
if (_shape == Shape.unknown && ancestor is Shape) {
if (_shape == null && ancestor is Shape) {
_changeShape(ancestor);
}
}

View File

@ -10,7 +10,7 @@ export 'package:rive/src/generated/shapes/path_vertex_base.dart';
abstract class PathVertex<T extends Weight> extends PathVertexBase {
T? _weight;
T? get weight => _weight;
Path get path => parent as Path;
Path? get path => parent as Path?;
@override
void update(int dirt) {}
final Vec2D _renderTranslation = Vec2D();
@ -21,16 +21,23 @@ abstract class PathVertex<T extends Weight> extends PathVertexBase {
y = value[1];
}
@override
void onAddedDirty() {
super.onAddedDirty();
_renderTranslation[0] = x;
_renderTranslation[1] = y;
}
@override
void xChanged(double from, double to) {
_renderTranslation[0] = to;
path.markPathDirty();
path?.markPathDirty();
}
@override
void yChanged(double from, double to) {
_renderTranslation[1] = to;
path.markPathDirty();
path?.markPathDirty();
}
@override

View File

@ -10,11 +10,8 @@ import 'package:rive/src/generated/shapes/shape_base.dart';
import 'package:collection/collection.dart';
export 'package:rive/src/generated/shapes/shape_base.dart';
class _UnknownShape extends Shape {}
class Shape extends ShapeBase with ShapePaintContainer {
final Set<Path> paths = {};
static final Shape unknown = _UnknownShape();
bool _wantWorldPath = false;
bool _wantLocalPath = false;
bool get wantWorldPath => _wantWorldPath;

View File

@ -6,30 +6,7 @@ import 'package:meta/meta.dart';
import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart';
import 'package:rive/src/rive_core/shapes/paint/stroke.dart';
class _UnknownShapePaintContainer extends ShapePaintContainer {
UnsupportedError get _error =>
UnsupportedError('Not expected to use the UnknownShapeContainer.');
@override
bool addDependent(Component dependent) =>
throw UnsupportedError('Not expected to use the UnknownShapeContainer.');
@override
bool addDirt(int value, {bool recurse = false}) => throw _error;
@override
void appendChild(Component child) => throw _error;
@override
void onFillsChanged() => throw _error;
@override
void onPaintMutatorChanged(ShapePaintMutator mutator) => throw _error;
@override
void onStrokesChanged() => throw _error;
@override
Mat2D get worldTransform => throw _error;
@override
Vec2D get worldTranslation => throw _error;
}
abstract class ShapePaintContainer {
static final ShapePaintContainer unknown = _UnknownShapePaintContainer();
final Set<Fill> fills = {};
final Set<Stroke> strokes = {};
void onPaintMutatorChanged(ShapePaintMutator mutator);

View File

@ -10,7 +10,7 @@ class StraightVertex extends StraightVertexBase {
String toString() => 'x[$x], y[$y], r[$radius]';
@override
void radiusChanged(double from, double to) {
path.markPathDirty();
path?.markPathDirty();
}
@override

View File

@ -70,7 +70,7 @@ abstract class TransformComponent extends TransformComponentBase {
void calculateWorldTransform() {
var parent = this.parent;
final chain = <TransformComponent>[this];
while (parent != ContainerComponent.unknown) {
while (parent != null) {
if (parent is TransformComponent) {
chain.insert(0, parent);
}
@ -85,7 +85,7 @@ abstract class TransformComponent extends TransformComponentBase {
@override
void buildDependencies() {
super.buildDependencies();
parent.addDependent(this);
parent?.addDependent(this);
}
void markTransformDirty() {
@ -120,7 +120,7 @@ abstract class TransformComponent extends TransformComponentBase {
}
@override
void parentChanged(ContainerComponent from, ContainerComponent to) {
void parentChanged(ContainerComponent? from, ContainerComponent? to) {
super.parentChanged(from, to);
markWorldTransformDirty();
}

View File

@ -195,7 +195,8 @@ class RiveFile {
if (object != null && object.validate()) {
InternalCoreHelper.markValid(object);
} else {
throw const RiveFormatErrorException('Rive file is corrupt.');
throw RiveFormatErrorException(
'Rive file is corrupt. Invalid $object.');
}
}
}

View File

@ -206,6 +206,7 @@ abstract class RiveRenderBox extends RenderBox {
if (contentWidth == 0 || contentHeight == 0) {
return;
}
double x = -1 * bounds[0] -
contentWidth / 2.0 -
(_alignment.x * contentWidth / 2.0);

View File

@ -1,5 +1,5 @@
abstract class Parentable<T> {
T get parent;
T? get parent;
}
/// Get the top most components (any child that has an ancestor in the set