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.

164 lines
5.2 KiB

2 years ago
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:my_flutter_puzzle/application/states/puzzle_state.dart';
  4. import 'package:my_flutter_puzzle/providers.dart';
  5. import 'package:my_flutter_puzzle/res/puzzle_constants.dart';
  6. import 'package:my_flutter_puzzle/screens/puzzle/top_bar.dart';
  7. import 'package:my_flutter_puzzle/utils/puzzle_solver.dart';
  8. import 'package:my_flutter_puzzle/widgets/solo_screen/solo_screen_export.dart';
  9. import 'package:rive/rive.dart';
  10. import '../../models/puzzle_data.dart';
  11. class SoloScreenLarge extends ConsumerStatefulWidget {
  12. const SoloScreenLarge({
  13. required this.solverClient,
  14. required this.initialPuzzleData,
  15. required this.puzzleSize,
  16. required this.puzzleType,
  17. required this.riveController,
  18. Key? key,
  19. }) : super(key: key);
  20. final PuzzleSolverClient solverClient;
  21. final PuzzleData initialPuzzleData;
  22. final int puzzleSize;
  23. final String puzzleType;
  24. final RiveAnimationController riveController;
  25. @override
  26. ConsumerState<ConsumerStatefulWidget> createState() => _SoloScreenLargeState();
  27. }
  28. class _SoloScreenLargeState extends ConsumerState<SoloScreenLarge> {
  29. late final PuzzleSolverClient _solverClient;
  30. late final int _puzzleSize;
  31. late final PuzzleData _initialPuzzleData;
  32. late final String _puzzleType;
  33. late final RiveAnimationController _riveController;
  34. bool _isStartPressed = false;
  35. @override
  36. void initState() {
  37. _solverClient = widget.solverClient;
  38. _puzzleSize = widget.puzzleSize;
  39. _initialPuzzleData = widget.initialPuzzleData;
  40. _puzzleType = widget.puzzleType;
  41. _riveController = widget.riveController;
  42. super.initState();
  43. }
  44. @override
  45. Widget build(BuildContext context) {
  46. ref.listen(puzzleNotifierProvider(_solverClient), (previous, PuzzleState next) {
  47. if (next is PuzzleSolved) {
  48. // TODO: Add celebration
  49. }
  50. if (next is PuzzleInitializing) {
  51. setState(() {
  52. _isStartPressed = true;
  53. });
  54. }
  55. });
  56. var fontSize = 70.0;
  57. var boardSize = 450.0;
  58. var spacing = 5;
  59. var eachBoxSize = (boardSize / _puzzleSize) - (spacing * (_puzzleSize - 1));
  60. return Scaffold(
  61. backgroundColor: Theme.of(context).backgroundColor,
  62. body: Row(
  63. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  64. children: [
  65. Padding(
  66. padding: const EdgeInsets.only(left: 56.0),
  67. child: Column(
  68. mainAxisAlignment: MainAxisAlignment.center,
  69. crossAxisAlignment: CrossAxisAlignment.start,
  70. children: [
  71. Row(),
  72. Text(
  73. _puzzleType,
  74. style: const TextStyle(
  75. fontSize: 18,
  76. fontWeight: FontWeight.w500,
  77. color: Colors.white,
  78. ),
  79. ),
  80. const SizedBox(height: 8),
  81. const Text(
  82. 'Puzzle',
  83. style: TextStyle(
  84. fontSize: 58,
  85. fontWeight: FontWeight.w500,
  86. color: Colors.white,
  87. ),
  88. ),
  89. const Text(
  90. 'Challenge',
  91. style: TextStyle(
  92. fontSize: 58,
  93. fontWeight: FontWeight.w500,
  94. color: Colors.white,
  95. ),
  96. ),
  97. const SizedBox(height: 32),
  98. MovesTilesWidget(solverClient: _solverClient),
  99. const SizedBox(height: 32),
  100. GameButtonWidget(
  101. solverClient: _solverClient,
  102. initialPuzzleData: _initialPuzzleData,
  103. ),
  104. ],
  105. ),
  106. ),
  107. SingleChildScrollView(
  108. child: Column(
  109. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  110. children: [
  111. const TimerWidget(
  112. fontSize: 40,
  113. ),
  114. const SizedBox(height: 36),
  115. PuzzleWidget(
  116. solverClient: _solverClient,
  117. boardSize: boardSize,
  118. eachBoxSize: eachBoxSize,
  119. initialPuzzleData: _initialPuzzleData,
  120. fontSize: fontSize,
  121. kInitialSpeed: kInitialSpeed,
  122. ),
  123. const SizedBox(height: 30),
  124. ],
  125. ),
  126. ),
  127. Column(
  128. mainAxisSize: MainAxisSize.max,
  129. children: [
  130. const Spacer(),
  131. CountdownWidget(
  132. isStartPressed: _isStartPressed,
  133. onFinish: () {
  134. ref.read(timerNotifierProvider.notifier).startTimer();
  135. setState(() {
  136. _isStartPressed = false;
  137. });
  138. },
  139. initialSpeed: kInitialSpeed,
  140. ),
  141. const Spacer(),
  142. AnimatedDash(
  143. boardSize: boardSize * 0.8,
  144. riveController: _riveController,
  145. onInit: (_) => setState(() {}),
  146. ),
  147. ],
  148. ),
  149. // SizedBox(),
  150. ],
  151. ),
  152. );
  153. }
  154. }