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.
|
|
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.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';
class ImageSplitterNotifier extends StateNotifier<ImageSplitterState> { final ImageSplitter _splitter;
ImageSplitterNotifier(this._splitter) : super(const ImageSplitterState());
void getInitialImages({required int puzzleSize, required String imagePath}) async { state = const ImageSplitterState.generating();
try { final data = await rootBundle.load(imagePath); final imageBytes = data.buffer.asUint8List(); final _splitter = ImageSplitter();
final palette = await _splitter.getImagePalette(AssetImage(imagePath)); final images = await _splitter.runSplitterIsolate(imageBytes, puzzleSize);
state = ImageSplitterState.complete(Image.asset(imagePath), images, palette); } catch (e) { state = ImageSplitterState.error(message: e.toString()); } } }
|