zerochill
zerochill

Reputation: 746

Flutter Image Compress giving result as null

Compressed is coming out as null

File compressed = await FlutterImageCompress.compressAndGetFile(
        img.path,
        img.path.split('/').last,
        quality: 80,
      );

      ref = firebase_storage.FirebaseStorage.instance
          .ref()
          .child('postimages/${Path.basename(img.path)}');
      await ref.putFile(compressed);

This is what the error I am getting

E/flutter (12851): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception:
NoSuchMethodError: The getter 'absolute' was called on null.
E/flutter (12851): Receiver: null
E/flutter (12851): Tried calling: absolute
E/flutter (12851): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (12851): #1 Reference.putFile
package:firebase_storage/src/reference.dart:126
E/flutter (12851): #2 _AddImageState.uploadFile
package:softclaw/…/addpost/addimage.dart:228
E/flutter (12851):
E/flutter (12851):

Upvotes: 1

Views: 1272

Answers (1)

zerochill
zerochill

Reputation: 746

This will work perfectly fine

final imageUri = Uri.parse(img.path);
      final String outputUri = imageUri.resolve('./output.webp').toString();
      print(imageUri.toFilePath());

      File compressed = await FlutterImageCompress.compressAndGetFile(
          img.path, outputUri,
          quality: 80, format: CompressFormat.webp);
      print(img.path);
      print(outputUri);

      ref = firebase_storage.FirebaseStorage.instance
          .ref()
          .child('postimages/${Path.basename(img.path)}');
      await ref.putFile(compressed);
      _imageName.add(await ref.getDownloadURL());
    }

Upvotes: 1

Related Questions