Browse Source

fix some bug

handle finish timer state
master
mohsen zamani 2 years ago
parent
commit
3eb46e4836
  1. 1
      lib/main.dart
  2. 26
      lib/screens/photo/photo_screen_large.dart
  3. 76
      lib/widgets/photo_screen/image_viewer.dart
  4. 3
      lib/widgets/solo_screen/game_button_widget.dart
  5. 4
      lib/widgets/solo_screen/puzzle_widget/puzzle_board.dart

1
lib/main.dart

@ -25,6 +25,7 @@ class MyApp extends StatelessWidget {
DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight, DeviceOrientation.landscapeRight,
]); ]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
return BlocProvider( return BlocProvider(
create: (context) => CountDownTimerCubit(), create: (context) => CountDownTimerCubit(),
child: MaterialApp( child: MaterialApp(

26
lib/screens/photo/photo_screen_large.dart

@ -80,6 +80,9 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
_previousImage = next.image; _previousImage = next.image;
_previousPalette = next.palette; _previousPalette = next.palette;
}); });
ref.read(puzzleNotifierProvider(_solverClient).notifier).initializePuzzle(
initialPuzzleData: _initialPuzzleData,
);
} }
}); });
@ -100,13 +103,18 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Visibility(
visible: !_isStartPressed,
child: ImageViewer(
puzzleSize: _puzzleSize,
previousImage: _previousImage,
previousPalette: _previousPalette,
imageSize: 200,
),
),
const SizedBox(height: 32), const SizedBox(height: 32),
MovesTilesWidget(solverClient: _solverClient, fontSize: 16), MovesTilesWidget(solverClient: _solverClient, fontSize: 16),
const SizedBox(height: 32), const SizedBox(height: 32),
GameButtonWidget(
solverClient: _solverClient,
initialPuzzleData: _initialPuzzleData,
),
], ],
), ),
), ),
@ -188,7 +196,6 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
CountdownWidget( CountdownWidget(
isStartPressed: _isStartPressed, isStartPressed: _isStartPressed,
onFinish: () { onFinish: () {
// ref.read(timerNotifierProvider.notifier).startTimer();
BlocProvider.of<CountDownTimerCubit>(context).start(); BlocProvider.of<CountDownTimerCubit>(context).start();
setState(() { setState(() {
_isStartPressed = false; _isStartPressed = false;
@ -196,15 +203,6 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
}, },
initialSpeed: kInitialSpeed, initialSpeed: kInitialSpeed,
), ),
Visibility(
visible: !_isStartPressed,
child: ImageViewer(
puzzleSize: _puzzleSize,
previousImage: _previousImage,
previousPalette: _previousPalette,
imageSize: 200,
),
),
], ],
), ),
], ],

76
lib/widgets/photo_screen/image_viewer.dart

@ -24,17 +24,10 @@ class ImageViewer extends ConsumerWidget {
final state = ref.watch(imageSplitterNotifierProvider); final state = ref.watch(imageSplitterNotifierProvider);
return state.maybeWhen( return state.maybeWhen(
() => const SizedBox(), () => const SizedBox(),
complete: (image, images, palette) => Padding(
padding: const EdgeInsets.only(right: 0.0),
child: Column(
complete: (image, images, palette) => Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
// border: Border.all(color: Colors.white, width: 3),
),
child: ClipRRect(
ClipRRect(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
child: Image( child: Image(
image: image.image, image: image.image,
@ -42,73 +35,8 @@ class ImageViewer extends ConsumerWidget {
width: imageSize, width: imageSize,
), ),
), ),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: SizedBox(
width: imageSize,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 4,
horizontal: 16,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: imageSize / 5,
height: imageSize / 5,
decoration: BoxDecoration(
color: palette.colors.elementAt(0),
shape: BoxShape.circle,
border: Border.all(
color: Colors.white60,
width: 3,
),
),
),
Container(
width: imageSize / 5,
height: imageSize / 5,
decoration: BoxDecoration(
color: palette.colors.elementAt(1),
shape: BoxShape.circle,
border: Border.all(
color: Colors.white60,
width: 3,
),
),
),
Container(
width: imageSize / 5,
height: imageSize / 5,
decoration: BoxDecoration(
color: palette.colors.elementAt(2),
shape: BoxShape.circle,
border: Border.all(
color: Colors.white60,
width: 3,
),
),
),
], ],
), ),
),
),
),
const SizedBox(height: 16),
// PickImageButton(
// text: 'Pick Image',
// onTap: () => ref
// .read(imageSplitterNotifierProvider.notifier)
// .generateImages(
// picker: imagePicker,
// puzzleSize: puzzleSize,
// ),
// ),
],
),
),
orElse: () => previousImage != null orElse: () => previousImage != null
? Padding( ? Padding(
padding: const EdgeInsets.only(right: 0.0), padding: const EdgeInsets.only(right: 0.0),

3
lib/widgets/solo_screen/game_button_widget.dart

@ -1,11 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.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/models/puzzle_data.dart';
import 'package:my_flutter_puzzle/providers.dart'; import 'package:my_flutter_puzzle/providers.dart';
import 'package:my_flutter_puzzle/utils/puzzle_solver.dart'; import 'package:my_flutter_puzzle/utils/puzzle_solver.dart';
import 'game_button_widget/puzzle_game_button.dart'; import 'game_button_widget/puzzle_game_button.dart';
class GameButtonWidget extends StatelessWidget { class GameButtonWidget extends StatelessWidget {

4
lib/widgets/solo_screen/puzzle_widget/puzzle_board.dart

@ -59,7 +59,7 @@ class PuzzleBoard extends ConsumerWidget {
elevation: 4, elevation: 4,
color: Theme.of(context).colorScheme.primary.withOpacity(isEnabled ? 1 : 0.5), color: Theme.of(context).colorScheme.primary.withOpacity(isEnabled ? 1 : 0.5),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadius),
borderRadius: BorderRadius.circular(10),
), ),
child: SizedBox( child: SizedBox(
height: eachBoxSize, height: eachBoxSize,
@ -82,7 +82,7 @@ class PuzzleBoard extends ConsumerWidget {
child: Opacity( child: Opacity(
opacity: isEnabled ? 1 : 0.5, opacity: isEnabled ? 1 : 0.5,
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(borderRadius),
borderRadius: BorderRadius.circular(10),
child: child:
images![int.parse(puzzleData.offsetMap.entries.toList()[i].key.toString()) - 1], images![int.parse(puzzleData.offsetMap.entries.toList()[i].key.toString()) - 1],
), ),

Loading…
Cancel
Save