import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:my_flutter_puzzle/application/states/image_splitter_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; final int level; const PuzzleStarterScreen({ Key? key, required this.duration, required this.puzzleSize, required this.image, required this.level, }) : 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(); ref.refresh(imageSplitterNotifierProvider); final state = ref.read(imageSplitterNotifierProvider); if (state is! ImageSplitterComplete) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) { ref.read(imageSplitterNotifierProvider.notifier).getInitialImages( puzzleSize: _puzzleSize, imagePath: widget.image, ); }); } ref.read(puzzleTypeNotifierProvider.notifier).changeToPhoto(); super.initState(); } @override Widget build(BuildContext context) { return AnimatedSwitcher( duration: const Duration(milliseconds: 400), child: PhotoScreen( solverClient: _solverClient, initialPuzzleData: _initialPuzzleData, level: widget.level, duration: widget.duration, puzzleSize: _puzzleSize, riveController: _riveController, ), ); } }