Image compress - Android / IOS

I've been leaching off of the community for a while now and I'd like to contribute.

Here's a working version of the image compress package. This only works on real Android devices, haven't tested on IOS yet but no reason it shouldn't work. Let me know if it doesn't.

This doesn't appear to work in test mode.

Takes a local upload and outputs an FFupload file.

Customize it as you like as per the official documentation here: flutter_image_compress | Flutter package (pub.dev)

// Automatic FlutterFlow imports

import '/backend/schema/structs/index.dart';

import '/backend/supabase/supabase.dart';

import '/flutter_flow/flutter_flow_theme.dart';

import '/flutter_flow/flutter_flow_util.dart';

import '/custom_code/actions/index.dart'; // Imports other custom actions

import '/flutter_flow/custom_functions.dart'; // Imports custom functions

import 'package:flutter/material.dart';

// Begin custom action code

// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:path_provider/path_provider.dart';

import 'dart:io';

import 'package:flutter_image_compress/flutter_image_compress.dart';

Future<FFUploadedFile> imgCompressSPBupload(FFUploadedFile file) async {

  Uint8List bytess = file.bytes!;

  // converts uint8LIst? to uint8List

  var result = await FlutterImageCompress.compressWithList(

    bytess,

    quality: 94,

  );

// you can add more params as per the documentation in the pub.dev package.

//uint8List is bytes.

  return FFUploadedFile(name: file.name, bytes: result);

}

5
5 replies