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

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:my_flutter_puzzle/providers.dart';
import 'package:my_flutter_puzzle/utils/puzzle_solver.dart';
import 'package:my_flutter_puzzle/widgets/solo_screen/moves_tiles_widget/moves_tiles_text.dart';
class MovesTilesWidget extends StatelessWidget {
final PuzzleSolverClient _solverClient;
final double fontSize;
final Function(int move, int tiles) callback;
const MovesTilesWidget({
Key? key,
required this.callback,
required PuzzleSolverClient solverClient,
this.fontSize = 24,
}) : _solverClient = solverClient,
super(key: key);
@override
Widget build(BuildContext context) {
return Consumer(
builder: (context, ref, child) {
final state = ref.watch(puzzleNotifierProvider(_solverClient));
return state.when(
() => MovesTilesText(
moves: 0,
tiles: 0,
fontSize: fontSize,
),
initializing: () => MovesTilesText(
moves: 0,
tiles: 0,
fontSize: fontSize,
),
scrambling: (_) => MovesTilesText(
moves: 0,
tiles: 0,
fontSize: fontSize,
),
current: (puzzleData) {
callback.call(puzzleData.moves, puzzleData.tiles);
return MovesTilesText(
moves: puzzleData.moves,
tiles: puzzleData.tiles,
fontSize: fontSize,
);
},
computingSolution: (puzzleData) {
callback.call(puzzleData.moves, puzzleData.tiles);
return MovesTilesText(
moves: puzzleData.moves,
tiles: puzzleData.tiles,
fontSize: fontSize,
);
},
autoSolving: (puzzleData) {
callback.call(puzzleData.moves, puzzleData.tiles);
return MovesTilesText(
moves: puzzleData.moves,
tiles: puzzleData.tiles,
fontSize: fontSize,
);
},
solved: (puzzleData) {
callback.call(puzzleData.moves, puzzleData.tiles);
return MovesTilesText(
moves: puzzleData.moves,
tiles: puzzleData.tiles,
fontSize: fontSize,
);
},
error: (_) => MovesTilesText(
moves: 0,
tiles: 0,
fontSize: fontSize,
),
);
},
);
}
}