@@ -21,61 +21,68 @@ class Hint extends StatefulWidget {
2121}
2222
2323class _HintState extends State <Hint > {
24- RiveFile ? _hintFile;
25- SMIBool ? _luminance;
26- SMIBool ? _theme;
24+ File ? _hintFile;
25+ late RiveWidgetController _controller;
26+ late StateMachine ? _stateController;
27+ late StateMachine ? _themeController;
28+ BooleanInput ? _luminance;
29+ BooleanInput ? _theme;
2730
2831 @override
2932 void initState () {
3033 super .initState ();
3134 preload ();
3235 }
3336
34- void preload () {
35- rootBundle.load (Media .animatedHint).then ((data) {
36- setState (() {
37- _hintFile = RiveFile .import (data);
38- });
39- });
37+ Future <void > preload () async {
38+ final data = await rootBundle.load (Media .animatedHint);
39+ _hintFile = await File .decode (
40+ data.buffer.asUint8List (),
41+ riveFactory: Factory .rive,
42+ );
43+ _controller = RiveWidgetController (_hintFile! );
44+ _onInit (_controller.artboard);
45+ setState (() {});
4046 }
4147
4248 void _onInit (Artboard artboard) {
43- final stateController = StateMachineController .fromArtboard (
44- artboard,
45- 'bulb' ,
46- );
47- final themeController = StateMachineController .fromArtboard (
48- artboard,
49- 'theme' ,
50- );
51- artboard
52- ..addController (stateController! )
53- ..addController (themeController! );
54- _luminance = stateController.findInput <bool >('pressed' )! as SMIBool ;
55- _theme = themeController.findInput <bool >('isDark' )! as SMIBool ;
49+ _stateController = artboard.stateMachine ('bulb' );
50+ _themeController = artboard.stateMachine ('theme' );
51+ _luminance = _stateController? .boolean ('pressed' );
52+ _theme = _themeController? .boolean ('isDark' );
5653 flipBulbByBooster (context.read <UserStatsCubit >().state);
57- _theme? .change ( context.read <ThemeCubit >().state is ThemeStateDark ) ;
54+ _theme? .value = context.read <ThemeCubit >().state is ThemeStateDark ;
5855 }
5956
6057 void flipBulbByBooster (UserStatsState statsState) {
6158 final userHasHint = statsState.progress.boosters.any (
6259 (booster) => booster is UseAHint && booster.boosterCount > 0 ,
6360 );
6461 if (userHasHint) {
65- _luminance? .change ( true ) ;
62+ _luminance? .value = true ;
6663 } else {
67- _luminance? .change ( false ) ;
64+ _luminance? .value = false ;
6865 }
6966 }
7067
68+ @override
69+ void dispose () {
70+ _controller.dispose ();
71+ _stateController? .dispose ();
72+ _themeController? .dispose ();
73+ _luminance? .dispose ();
74+ _theme? .dispose ();
75+ super .dispose ();
76+ }
77+
7178 @override
7279 Widget build (BuildContext context) {
7380 if (_hintFile == null ) return const SizedBox .shrink ();
7481 return Tooltip (
7582 message: 'Use a hint' ,
7683 child: BlocConsumer <ThemeCubit , ThemeState >(
7784 listener: (context, themeState) {
78- _theme? .change ( themeState is ThemeStateDark ) ;
85+ _theme? .value = themeState is ThemeStateDark ;
7986 },
8087 builder: (context, themeState) {
8188 return BlocConsumer <UserStatsCubit , UserStatsState >(
@@ -123,11 +130,10 @@ class _HintState extends State<Hint> {
123130 baseline: 45 ,
124131 child: SizedBox (
125132 width: 50 ,
126- child: RiveAnimation . direct (
133+ child: RiveWidget (
127134 key: UniqueKey (),
128- _hintFile! ,
129- fit: BoxFit .cover,
130- onInit: _onInit,
135+ controller: _controller,
136+ fit: Fit .cover,
131137 ),
132138 ),
133139 ),
0 commit comments