Open onderadaidenfit opened 11 months ago
Hi @onderadaidenfit I got error same you. Did you solve this issue?
@CaiJingLong , @AlexV525 , @behzodfaiziev please check issue? No solution?
@CaiJingLong , @AlexV525 , @behzodfaiziev please check issue? No solution?
I have the same issue. I'm trying to load and compress some images with compressAssetImage, and it's working fine on Android, but on Web I get an error similar to the one mentioned above:
This is my code:
class CompressedImageProvider {
static List<String> imagePaths = [];
static List<String> allAssetPaths = [];
static Map<String, Uint8List> compressedImages = {};
static Future<Uint8List> getCompressedAssetImage(String assetName) async {
var list = await FlutterImageCompress.compressAssetImage(
assetName,
minHeight: 200,
minWidth: 200,
quality: 96,
rotate: 180,
);
assert(list != null, "Failed to compress image: $assetName");
return list!;
}
static Future<void> init() async {
final assetManifest = await rootBundle.loadString('AssetManifest.json');
final Map<String, dynamic> manifest = json.decode(assetManifest);
allAssetPaths = manifest.keys.toList();
imagePaths = allAssetPaths
.where((path) => path.startsWith('assets/images'))
.toList();
for (var path in imagePaths) {
compressedImages[path] = await getCompressedAssetImage(path);
}
}
}
Which is executed in main:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await CompressedImageProvider.init();
runApp(
MaterialApp(
. . .
),
);
}
And here is the debug output:
Error: Expected a value of type 'Function', but got one of type 'Null'
dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 294:49 throw
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 127:3 castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 742:12 cast
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 143:17 as
dart-sdk/lib/_internal/js_shared/lib/js_util_patch.dart 77:5 getProperty
packages/flutter_image_compress_web/src/pica.dart 42:25 resizeWithList
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5 _async
packages/flutter_image_compress_web/src/pica.dart 34:33 resizeWithList
packages/flutter_image_compress_web/flutter_image_compress_web.dart 46:12 compressAssetImage
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50
I'm using flutter_image_compress 2.0.4
Never mind, the solution was posted on another thread, and it is even in the docs. Reading helps ^^' In case someone's still struggling with this:
add
<script src="https://unpkg.com/pica/dist/pica.min.js" ></script>
to index.html and do a flutter clean
_Originally posted by @pasanediri97 in https://github.com/fluttercandies/flutter_image_compress/issues/256#issuecomment-1680200332_
Version
2.0.4
Platforms
Web
Device Model
macbook chrome
flutter info
How to reproduce?
// 4. compress Uint8List and get another Uint8List. Android Studio Run Chrome(web) not working funtion Uint8List list -> FlutterImageCompress.compressWithList(...
[error](error:: Expected a value of type 'Function', but got one of type 'Null')
Logs
Example code (optional)
No response
Contact
ondertel@gmail.com