Browse Source

fix some bug

handle finish timer state
master
mohsen zamani 2 years ago
parent
commit
90bd2a4858
  1. 21
      lib/application/notifiers/image_splitter_notifier.dart
  2. 3
      lib/screens/photo/photo_screen_large.dart
  3. 20
      lib/utils/image_splitter.dart
  4. 5
      lib/widgets/photo_screen/image_viewer.dart
  5. 56
      pubspec.lock
  6. 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/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.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/image_splitter_state.dart';
import 'package:my_flutter_puzzle/res/strings.dart'; import 'package:my_flutter_puzzle/res/strings.dart';
import 'package:my_flutter_puzzle/utils/image_splitter.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()); 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());
}
}
} }

3
lib/screens/photo/photo_screen_large.dart

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_riverpod/flutter_riverpod.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/image_splitter_state.dart';
import 'package:my_flutter_puzzle/application/states/puzzle_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/cubits/count_down_timer_cubit.dart';
@ -43,7 +42,6 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
late final RiveAnimationController _riveController; late final RiveAnimationController _riveController;
bool _puzzleSolved = false; bool _puzzleSolved = false;
bool _isStartPressed = false; bool _isStartPressed = false;
final _imagePicker = ImagePicker();
final double _fontSize = 70.0; final double _fontSize = 70.0;
final double _boardSize = 280.0; final double _boardSize = 280.0;
final int _spacing = 4; final int _spacing = 4;
@ -201,7 +199,6 @@ class _SoloScreenLargeState extends ConsumerState<PhotoScreenLarge> {
Visibility( Visibility(
visible: !_isStartPressed, visible: !_isStartPressed,
child: ImageViewer( child: ImageViewer(
imagePicker: _imagePicker,
puzzleSize: _puzzleSize, puzzleSize: _puzzleSize,
previousImage: _previousImage, previousImage: _previousImage,
previousPalette: _previousPalette, previousPalette: _previousPalette,

20
lib/utils/image_splitter.dart

@ -3,7 +3,6 @@ import 'dart:developer';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:image/image.dart' as image_lib; import 'package:image/image.dart' as image_lib;
import 'package:image_picker/image_picker.dart';
import 'package:palette_generator/palette_generator.dart'; import 'package:palette_generator/palette_generator.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
@ -43,25 +42,6 @@ class ImageSplitter {
return paletteGenerator; 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 { Future<List<Image>> runSplitterIsolate(List<int> input, int size) async {
final Map<String, dynamic> data = { final Map<String, dynamic> data = {
'input': input, 'input': input,

5
lib/widgets/photo_screen/image_viewer.dart

@ -1,14 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.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/providers.dart';
// import 'package:my_flutter_puzzle/widgets/photo_screen/pick_image_button.dart';
import 'package:palette_generator/palette_generator.dart'; import 'package:palette_generator/palette_generator.dart';
class ImageViewer extends ConsumerWidget { class ImageViewer extends ConsumerWidget {
const ImageViewer({ const ImageViewer({
required this.imagePicker,
required this.puzzleSize, required this.puzzleSize,
required this.previousImage, required this.previousImage,
required this.previousPalette, required this.previousPalette,
@ -16,7 +12,6 @@ class ImageViewer extends ConsumerWidget {
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
final ImagePicker imagePicker;
final int puzzleSize; final int puzzleSize;
final Image? previousImage; final Image? previousImage;
final PaletteGenerator? previousPalette; final PaletteGenerator? previousPalette;

56
pubspec.lock

@ -193,14 +193,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.5.4" 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: crypto:
dependency: transitive dependency: transitive
description: description:
@ -278,14 +270,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.4" 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: flutter_riverpod:
dependency: "direct main" dependency: "direct main"
description: description:
@ -384,46 +368,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.3.0" 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: io:
dependency: transitive dependency: transitive
description: description:

1
pubspec.yaml

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

Loading…
Cancel
Save