mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-06-27 10:18:12 +08:00
More nnbd work
This commit is contained in:
@ -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,
|
||||
|
@ -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!,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user