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!,
),
),
),