You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.9 KiB

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<ConsumerStatefulWidget> createState() => _SoloScreenState();
}
class _SoloScreenState extends ConsumerState<PuzzleStarterScreen> {
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,
),
);
}
}