flutter_image_compress
flutter_image_compress copied to clipboard
Expected a value of type 'Function', but got one of type 'Null'
Version
2.0.4
Platforms
Web
Device Model
macbook chrome
flutter info
[✓] Flutter (Channel stable, 3.13.2, on macOS 13.5.2 22G91 darwin-x64, locale en-TR)
• Flutter version 3.13.2 on channel stable at /Volumes/disk2/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ff5b5b5fa6 (4 weeks ago), 2023-08-24 08:12:28 -0500
• Engine revision b20183e040
• Dart version 3.1.0
• DevTools version 2.25.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /Users/onderada/Library/Android/sdk
• Platform android-34, build-tools 33.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15A240d
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[✓] Connected device (4 available)
• Pixel 6 (mobile) • 18211FDF6002E5 • android-arm64 • Android 13 (API 33)
• iPhone (mobile) • 00008030-001148840A79802E • ios • iOS 17.0 21A329
• macOS (desktop) • macos • darwin-x64 • macOS 13.5.2 22G91 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 116.0.5845.187
[✓] Network resources
• All expected network resources are available.
• No issues found!
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
Expected a value of type 'Function', but got one of type 'Null'
Example code (optional)
No response
Contact
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/ddc_runtime/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