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.
 
 
 
 
 
 

145 lines
4.8 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/providers.dart';
import 'package:my_flutter_puzzle/res/puzzle_constants.dart';
import 'package:my_flutter_puzzle/screens/puzzle/top_bar.dart';
import 'package:my_flutter_puzzle/utils/puzzle_solver.dart';
import 'package:my_flutter_puzzle/widgets/solo_screen/countdown_overlay.dart';
import 'package:my_flutter_puzzle/widgets/solo_screen/solo_screen_export.dart';
import 'package:rive/rive.dart';
import '../../models/puzzle_data.dart';
class SoloScreenSmall extends ConsumerStatefulWidget {
const SoloScreenSmall({
required this.solverClient,
required this.initialPuzzleData,
required this.puzzleSize,
required this.puzzleType,
required this.riveController,
Key? key,
}) : super(key: key);
final PuzzleSolverClient solverClient;
final PuzzleData initialPuzzleData;
final int puzzleSize;
final String puzzleType;
final RiveAnimationController riveController;
@override
ConsumerState<ConsumerStatefulWidget> createState() => _SoloScreenLargeState();
}
class _SoloScreenLargeState extends ConsumerState<SoloScreenSmall> {
late final PuzzleSolverClient _solverClient;
late final int _puzzleSize;
late final PuzzleData _initialPuzzleData;
late final String _puzzleType;
late final RiveAnimationController _riveController;
bool _isStartPressed = false;
@override
void initState() {
_solverClient = widget.solverClient;
_puzzleSize = widget.puzzleSize;
_initialPuzzleData = widget.initialPuzzleData;
_puzzleType = widget.puzzleType;
_riveController = widget.riveController;
super.initState();
}
@override
Widget build(BuildContext context) {
ref.listen(puzzleNotifierProvider(_solverClient), (previous, PuzzleState next) {
if (next is PuzzleSolved) {
// TODO: Add celebration
}
if (next is PuzzleInitializing) {
setState(() {
_isStartPressed = true;
});
}
});
var fontSize = 48.0;
var boardSize = 300.0;
var spacing = 3;
var eachBoxSize = (boardSize / _puzzleSize) - (spacing * (_puzzleSize - 1));
return Stack(
children: [
Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: Stack(
children: [
Row(
children: [
const Spacer(),
AnimatedDash(
boardSize: boardSize / 1.5,
riveController: _riveController,
onInit: (_) => setState(() {}),
padding: const EdgeInsets.only(right: 16.0, bottom: 30),
),
],
),
SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(),
const SizedBox(height: 30),
const Text(
'Puzzle Challenge',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
const SizedBox(height: 8),
MovesTilesWidget(
solverClient: _solverClient,
fontSize: 22,
),
const SizedBox(height: 8),
const TimerWidget(fontSize: 24),
PuzzleWidget(
solverClient: _solverClient,
boardSize: boardSize,
eachBoxSize: eachBoxSize,
initialPuzzleData: _initialPuzzleData,
fontSize: fontSize,
kInitialSpeed: kInitialSpeed,
borderRadius: 16,
),
const SizedBox(height: 24),
GameButtonWidget(
solverClient: _solverClient,
initialPuzzleData: _initialPuzzleData,
padding: const EdgeInsets.only(top: 10.0, bottom: 9.0),
width: 130,
),
const SizedBox(height: 100),
],
),
),
],
),
),
CountdownOverlay(
isStartPressed: _isStartPressed,
onFinish: () {
ref.read(timerNotifierProvider.notifier).startTimer();
setState(() {
_isStartPressed = false;
});
},
initialSpeed: kInitialSpeed,
),
],
);
}
}