2 Commits

Author SHA1 Message Date
mohsen zamani 3eb46e4836 fix some bug 2 years ago
mohsen zamani 90bd2a4858 fix some bug 2 years ago
  1. 21
      lib/application/notifiers/image_splitter_notifier.dart
  2. 1
      lib/main.dart
  3. 29
      lib/screens/photo/photo_screen_large.dart
  4. 20
      lib/utils/image_splitter.dart
  5. 81
      lib/widgets/photo_screen/image_viewer.dart
  6. 3
      lib/widgets/solo_screen/game_button_widget.dart
  7. 4
      lib/widgets/solo_screen/puzzle_widget/puzzle_board.dart
  8. 56
      pubspec.lock
  9. 1
      pubspec.yaml

21
lib/application/notifiers/image_splitter_notifier.dart

@ -3,7 +3,6 @@ import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_picker/image_picker.dart';
import 'package:my_flutter_puzzle/application/states/image_splitter_state.dart';
import 'package:my_flutter_puzzle/res/strings.dart';
import 'package:my_flutter_puzzle/utils/image_splitter.dart';
@ -29,24 +28,4 @@ class ImageSplitterNotifier extends StateNotifier<ImageSplitterState> {
state = ImageSplitterState.error(message: e.toString());
}
}
void generateImages({required ImagePicker picker, required int puzzleSize}) async {
state = const ImageSplitterState.generating();
try {
final imageBytesPalette = await _splitter.getImage(picker: picker);
if (imageBytesPalette != null) {
final image = imageBytesPalette.item1;
final imageBytes = imageBytesPalette.item2;
final palette = imageBytesPalette.item3;
log('Image tuple retrieved');
final images = await _splitter.runSplitterIsolate(imageBytes, puzzleSize);
state = ImageSplitterState.complete(image, images, palette);
}
} catch (e) {
debugPrint('Error: $e');
state = ImageSplitterState.error(message: e.toString());
}
}
}

1
lib/main.dart

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

29
lib/screens/photo/photo_screen_large.dart

@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_picker/image_picker.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';
@ -43,7 +42,6 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
late final RiveAnimationController _riveController;
bool _puzzleSolved = false;
bool _isStartPressed = false;
final _imagePicker = ImagePicker();
final double _fontSize = 70.0;
final double _boardSize = 280.0;
final int _spacing = 4;
@ -82,6 +80,9 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
_previousImage = next.image;
_previousPalette = next.palette;
});
ref.read(puzzleNotifierProvider(_solverClient).notifier).initializePuzzle(
initialPuzzleData: _initialPuzzleData,
);
}
});
@ -102,13 +103,18 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Visibility(
visible: !_isStartPressed,
child: ImageViewer(
puzzleSize: _puzzleSize,
previousImage: _previousImage,
previousPalette: _previousPalette,
imageSize: 200,
),
),
const SizedBox(height: 32),
MovesTilesWidget(solverClient: _solverClient, fontSize: 16),
const SizedBox(height: 32),
GameButtonWidget(
solverClient: _solverClient,
initialPuzzleData: _initialPuzzleData,
),
],
),
),
@ -190,7 +196,6 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
CountdownWidget(
isStartPressed: _isStartPressed,
onFinish: () {
// ref.read(timerNotifierProvider.notifier).startTimer();
BlocProvider.of<CountDownTimerCubit>(context).start();
setState(() {
_isStartPressed = false;
@ -198,16 +203,6 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
},
initialSpeed: kInitialSpeed,
),
Visibility(
visible: !_isStartPressed,
child: ImageViewer(
imagePicker: _imagePicker,
puzzleSize: _puzzleSize,
previousImage: _previousImage,
previousPalette: _previousPalette,
imageSize: 200,
),
),
],
),
],

20
lib/utils/image_splitter.dart

@ -3,7 +3,6 @@ import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image/image.dart' as image_lib;
import 'package:image_picker/image_picker.dart';
import 'package:palette_generator/palette_generator.dart';
import 'package:tuple/tuple.dart';
@ -43,25 +42,6 @@ class ImageSplitter {
return paletteGenerator;
}
Future<Tuple3<Image, Uint8List, PaletteGenerator>?> getImage({required ImagePicker picker}) async {
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
// final imageFile = File(pickedFile.path);
// final image = Image.file(File(pickedFile.path));
final image = Image.memory(await pickedFile.readAsBytes());
final palette = await getImagePalette(image.image);
// final PaletteGenerator palette = await getImagePalette(
// FileImage(imageFile),
// );
final bytes = await pickedFile.readAsBytes();
log('Image properties retrieved');
return Tuple3(image, bytes, palette);
}
return null;
}
Future<List<Image>> runSplitterIsolate(List<int> input, int size) async {
final Map<String, dynamic> data = {
'input': input,

81
lib/widgets/photo_screen/image_viewer.dart

@ -1,14 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_picker/image_picker.dart';
import 'package:my_flutter_puzzle/providers.dart';
// import 'package:my_flutter_puzzle/widgets/photo_screen/pick_image_button.dart';
import 'package:palette_generator/palette_generator.dart';
class ImageViewer extends ConsumerWidget {
const ImageViewer({
required this.imagePicker,
required this.puzzleSize,
required this.previousImage,
required this.previousPalette,
@ -16,7 +12,6 @@ class ImageViewer extends ConsumerWidget {
Key? key,
}) : super(key: key);
final ImagePicker imagePicker;
final int puzzleSize;
final Image? previousImage;
final PaletteGenerator? previousPalette;
@ -29,17 +24,10 @@ class ImageViewer extends ConsumerWidget {
final state = ref.watch(imageSplitterNotifierProvider);
return state.maybeWhen(
() => const SizedBox(),
complete: (image, images, palette) => Padding(
padding: const EdgeInsets.only(right: 0.0),
child: Column(
complete: (image, images, palette) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
// border: Border.all(color: Colors.white, width: 3),
),
child: ClipRRect(
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image(
image: image.image,
@ -47,73 +35,8 @@ class ImageViewer extends ConsumerWidget {
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
? Padding(
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_bloc/flutter_bloc.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/providers.dart';
import 'package:my_flutter_puzzle/utils/puzzle_solver.dart';
import 'game_button_widget/puzzle_game_button.dart';
class GameButtonWidget extends StatelessWidget {

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

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

56
pubspec.lock

@ -193,14 +193,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.4"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "0b0036e8cccbfbe0555fd83c1d31a6f30b77a96b598b35a5d36dd41f718695e9"
url: "https://pub.dev"
source: hosted
version: "0.3.3+4"
crypto:
dependency: transitive
description:
@ -278,14 +270,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: "4bef634684b2c7f3468c77c766c831229af829a0cd2d4ee6c1b99558bd14e5d2"
url: "https://pub.dev"
source: hosted
version: "2.0.8"
flutter_riverpod:
dependency: "direct main"
description:
@ -384,46 +368,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.3.0"
image_picker:
dependency: "direct main"
description:
name: image_picker
sha256: "22207768556b82d55ec70166824350fee32298732d5efa4d6e756f848f51f66a"
url: "https://pub.dev"
source: hosted
version: "0.8.6+3"
image_picker_android:
dependency: transitive
description:
name: image_picker_android
sha256: "68d067baf7f6e401b1124ee83dd6967e67847314250fd68012aab34a69beb344"
url: "https://pub.dev"
source: hosted
version: "0.8.5+7"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
sha256: "66fc6e3877bbde82c33d122f3588777c3784ac5bd7d1cdd79213ef7aecb85b34"
url: "https://pub.dev"
source: hosted
version: "2.1.11"
image_picker_ios:
dependency: transitive
description:
name: image_picker_ios
sha256: "39aa70b5f1e5e7c94585b9738632d5fdb764a5655e40cd9e7b95fbd2fc50c519"
url: "https://pub.dev"
source: hosted
version: "0.8.6+9"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
sha256: "1991219d9dbc42a99aff77e663af8ca51ced592cd6685c9485e3458302d3d4f8"
url: "https://pub.dev"
source: hosted
version: "2.6.3"
io:
dependency: transitive
description:

1
pubspec.yaml

@ -20,7 +20,6 @@ dependencies:
image: ^3.1.1
palette_generator: ^0.3.3
path_provider: ^2.0.8
image_picker: ^0.8.4+5
flutter_bloc: ^8.1.1
font_awesome_flutter: ^9.2.0
crop: ^0.5.2

Loading…
Cancel
Save