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.
219 lines
8.4 KiB
219 lines
8.4 KiB
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:my_flutter_puzzle/application/states/image_splitter_state.dart';
|
|
import 'package:my_flutter_puzzle/application/states/puzzle_state.dart';
|
|
import 'package:my_flutter_puzzle/cubits/count_down_timer_cubit.dart';
|
|
import 'package:my_flutter_puzzle/models/puzzle_data.dart';
|
|
import 'package:my_flutter_puzzle/providers.dart';
|
|
import 'package:my_flutter_puzzle/res/puzzle_constants.dart';
|
|
import 'package:my_flutter_puzzle/utils/puzzle_solver.dart';
|
|
import 'package:my_flutter_puzzle/utils/utils.dart';
|
|
import 'package:my_flutter_puzzle/widgets/photo_screen/image_viewer.dart';
|
|
import 'package:my_flutter_puzzle/widgets/solo_screen/count_down_timer_widget.dart';
|
|
import 'package:my_flutter_puzzle/widgets/solo_screen/solo_screen_export.dart';
|
|
import 'package:palette_generator/palette_generator.dart';
|
|
import 'package:rive/rive.dart';
|
|
|
|
class PhotoScreenLarge extends ConsumerStatefulWidget {
|
|
const PhotoScreenLarge({
|
|
required this.solverClient,
|
|
required this.initialPuzzleData,
|
|
required this.puzzleSize,
|
|
required this.riveController,
|
|
required this.duration,
|
|
Key? key,
|
|
}) : super(key: key);
|
|
|
|
final PuzzleSolverClient solverClient;
|
|
final PuzzleData initialPuzzleData;
|
|
final int puzzleSize;
|
|
final int duration;
|
|
final RiveAnimationController riveController;
|
|
|
|
@override
|
|
ConsumerState<ConsumerStatefulWidget> createState() => _SoloScreenLargeState();
|
|
}
|
|
|
|
class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
|
|
late final PuzzleSolverClient _solverClient;
|
|
late final int _puzzleSize;
|
|
late final PuzzleData _initialPuzzleData;
|
|
late final RiveAnimationController _riveController;
|
|
bool _puzzleSolved = false;
|
|
bool _isStartPressed = false;
|
|
final double _fontSize = 70.0;
|
|
final double _boardSize = 280.0;
|
|
final int _spacing = 4;
|
|
late double _eachBoxSize;
|
|
List<Image>? _previousImages;
|
|
Image? _previousImage;
|
|
PaletteGenerator? _previousPalette;
|
|
|
|
@override
|
|
void initState() {
|
|
_solverClient = widget.solverClient;
|
|
_puzzleSize = widget.puzzleSize;
|
|
_eachBoxSize = (_boardSize / _puzzleSize) - (_spacing * (_puzzleSize - 1));
|
|
_initialPuzzleData = widget.initialPuzzleData;
|
|
_riveController = widget.riveController;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
ref.listen(puzzleNotifierProvider(_solverClient), (previous, PuzzleState next) {
|
|
if (next is PuzzleInitializing) {
|
|
setState(() {
|
|
_isStartPressed = true;
|
|
});
|
|
}
|
|
if (next is PuzzleSolved) {
|
|
_puzzleSolved = true;
|
|
}
|
|
});
|
|
|
|
ref.listen(imageSplitterNotifierProvider, (previous, next) {
|
|
if (next is ImageSplitterComplete) {
|
|
setState(() {
|
|
_previousImages = next.images;
|
|
_previousImage = next.image;
|
|
_previousPalette = next.palette;
|
|
});
|
|
}
|
|
});
|
|
|
|
return WillPopScope(
|
|
onWillPop: () async {
|
|
BlocProvider.of<CountDownTimerCubit>(context).stop();
|
|
return true;
|
|
},
|
|
child: Scaffold(
|
|
backgroundColor: Theme.of(context).colorScheme.background,
|
|
body: SafeArea(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.symmetric(horizontal: 10),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const SizedBox(height: 32),
|
|
MovesTilesWidget(solverClient: _solverClient, fontSize: 16),
|
|
const SizedBox(height: 32),
|
|
GameButtonWidget(
|
|
solverClient: _solverClient,
|
|
initialPuzzleData: _initialPuzzleData,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
CountDownTimerWidget(
|
|
duration: widget.duration,
|
|
finishCallback: () {
|
|
if (!_puzzleSolved) {
|
|
Utils.instance.showToast(context, 'TimeOut');
|
|
Future.delayed(const Duration(milliseconds: 1500), () {
|
|
Navigator.pop(context);
|
|
});
|
|
}
|
|
},
|
|
),
|
|
const SizedBox(height: 12),
|
|
Consumer(
|
|
builder: (context, ref, child) {
|
|
final state = ref.watch(imageSplitterNotifierProvider);
|
|
|
|
return state.maybeWhen(
|
|
() => PuzzleWidget(
|
|
solverClient: _solverClient,
|
|
boardSize: _boardSize,
|
|
eachBoxSize: _eachBoxSize,
|
|
initialPuzzleData: _initialPuzzleData,
|
|
fontSize: _fontSize,
|
|
images: _previousImages,
|
|
kInitialSpeed: kInitialSpeed,
|
|
),
|
|
complete: (image, images, palette) {
|
|
_previousImages = images;
|
|
_previousImage = image;
|
|
_previousPalette = palette;
|
|
|
|
return PuzzleWidget(
|
|
solverClient: _solverClient,
|
|
boardSize: _boardSize,
|
|
eachBoxSize: _eachBoxSize,
|
|
initialPuzzleData: _initialPuzzleData,
|
|
fontSize: _fontSize,
|
|
images: images,
|
|
kInitialSpeed: kInitialSpeed,
|
|
);
|
|
},
|
|
orElse: () => PuzzleWidget(
|
|
solverClient: _solverClient,
|
|
boardSize: _boardSize,
|
|
eachBoxSize: _eachBoxSize,
|
|
initialPuzzleData: _initialPuzzleData,
|
|
fontSize: _fontSize,
|
|
images: _previousImages,
|
|
kInitialSpeed: kInitialSpeed,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 30),
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.symmetric(horizontal: 10),
|
|
child: Stack(
|
|
children: [
|
|
AnimatedDash(
|
|
boardSize: _boardSize * 0.8,
|
|
riveController: _riveController,
|
|
onInit: (_) => setState(() {}),
|
|
),
|
|
Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CountdownWidget(
|
|
isStartPressed: _isStartPressed,
|
|
onFinish: () {
|
|
// ref.read(timerNotifierProvider.notifier).startTimer();
|
|
BlocProvider.of<CountDownTimerCubit>(context).start();
|
|
setState(() {
|
|
_isStartPressed = false;
|
|
});
|
|
},
|
|
initialSpeed: kInitialSpeed,
|
|
),
|
|
Visibility(
|
|
visible: !_isStartPressed,
|
|
child: ImageViewer(
|
|
puzzleSize: _puzzleSize,
|
|
previousImage: _previousImage,
|
|
previousPalette: _previousPalette,
|
|
imageSize: 200,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|