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.

82 lines
2.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:my_flutter_puzzle/providers.dart';
  4. import 'package:my_flutter_puzzle/utils/puzzle_solver.dart';
  5. import 'package:my_flutter_puzzle/widgets/solo_screen/moves_tiles_widget/moves_tiles_text.dart';
  6. class MovesTilesWidget extends StatelessWidget {
  7. final PuzzleSolverClient _solverClient;
  8. final double fontSize;
  9. final Function(int move, int tiles) callback;
  10. const MovesTilesWidget({
  11. Key? key,
  12. required this.callback,
  13. required PuzzleSolverClient solverClient,
  14. this.fontSize = 24,
  15. }) : _solverClient = solverClient,
  16. super(key: key);
  17. @override
  18. Widget build(BuildContext context) {
  19. return Consumer(
  20. builder: (context, ref, child) {
  21. final state = ref.watch(puzzleNotifierProvider(_solverClient));
  22. return state.when(
  23. () => MovesTilesText(
  24. moves: 0,
  25. tiles: 0,
  26. fontSize: fontSize,
  27. ),
  28. initializing: () => MovesTilesText(
  29. moves: 0,
  30. tiles: 0,
  31. fontSize: fontSize,
  32. ),
  33. scrambling: (_) => MovesTilesText(
  34. moves: 0,
  35. tiles: 0,
  36. fontSize: fontSize,
  37. ),
  38. current: (puzzleData) {
  39. callback.call(puzzleData.moves, puzzleData.tiles);
  40. return MovesTilesText(
  41. moves: puzzleData.moves,
  42. tiles: puzzleData.tiles,
  43. fontSize: fontSize,
  44. );
  45. },
  46. computingSolution: (puzzleData) {
  47. callback.call(puzzleData.moves, puzzleData.tiles);
  48. return MovesTilesText(
  49. moves: puzzleData.moves,
  50. tiles: puzzleData.tiles,
  51. fontSize: fontSize,
  52. );
  53. },
  54. autoSolving: (puzzleData) {
  55. callback.call(puzzleData.moves, puzzleData.tiles);
  56. return MovesTilesText(
  57. moves: puzzleData.moves,
  58. tiles: puzzleData.tiles,
  59. fontSize: fontSize,
  60. );
  61. },
  62. solved: (puzzleData) {
  63. callback.call(puzzleData.moves, puzzleData.tiles);
  64. return MovesTilesText(
  65. moves: puzzleData.moves,
  66. tiles: puzzleData.tiles,
  67. fontSize: fontSize,
  68. );
  69. },
  70. error: (_) => MovesTilesText(
  71. moves: 0,
  72. tiles: 0,
  73. fontSize: fontSize,
  74. ),
  75. );
  76. },
  77. );
  78. }
  79. }