import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:my_flutter_puzzle/application/states/puzzle_state.dart'; import 'package:my_flutter_puzzle/models/puzzle_data.dart'; import 'package:my_flutter_puzzle/providers.dart'; import 'package:my_flutter_puzzle/screens/photo/photo_screen.dart'; import 'package:my_flutter_puzzle/utils/puzzle_solver.dart'; import 'package:rive/rive.dart'; class PuzzleStarterScreen extends ConsumerStatefulWidget { final int puzzleSize; final String image; final int duration; const PuzzleStarterScreen({ Key? key, required this.duration, required this.puzzleSize, required this.image, }) : super(key: key); @override ConsumerState createState() => _SoloScreenState(); } class _SoloScreenState extends ConsumerState { late final PuzzleSolverClient _solverClient; late RiveAnimationController _riveController; late final int _puzzleSize; late final PuzzleData _initialPuzzleData; @override void initState() { _puzzleSize = widget.puzzleSize; _riveController = SimpleAnimation('idle'); _solverClient = PuzzleSolverClient(size: _puzzleSize); _initialPuzzleData = ref.read(puzzleNotifierProvider(_solverClient).notifier).generateInitialPuzzle(); super.initState(); } @override Widget build(BuildContext context) { ref.listen(puzzleNotifierProvider(_solverClient), (previous, PuzzleState next) { if (next is PuzzleSolved) { ref.read(timerNotifierProvider.notifier).stopTimer(); } }); return AnimatedSwitcher( duration: const Duration(milliseconds: 400), child: PhotoScreen( solverClient: _solverClient, initialPuzzleData: _initialPuzzleData, puzzleSize: _puzzleSize, riveController: _riveController, ), ); } }