compressimage 0.1.1 copy "compressimage: ^0.1.1" to clipboard
compressimage: ^0.1.1 copied to clipboard

Compress pictures taken with JPG quality

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:compressimage/compressimage.dart';

Future<Null> main() async {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Future<File> _futureImage;
  File _imageFile;

  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  @override
  initState() {
    super.initState();
  }

  Future compressNow() async {
    //_futureImage = ImagePicker.pickImage(source: ImageSource.camera);
    //Source of the image in _futureImage
    _imageFile = await _futureImage;
    print("FILE SIZE BEFORE: " + _imageFile.lengthSync().toString());
    await CompressImage.compress(imageSrc: _imageFile.path, desiredQuality: 80); //desiredQuality ranges from 0 to 100
    print("FILE SIZE  AFTER: " + _imageFile.lengthSync().toString());

    setState(() {
      _imageFile;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Compress Image Example App'),
        ),
        body: new Center(
          child: _imageFile == null
              ? new Text('No image selected.')
              : new Image.file(_imageFile),
        ),
        floatingActionButton: new FloatingActionButton(
          onPressed: () {
            compressNow();
          },
          tooltip: 'Pick Image',
          child: new Icon(Icons.add_a_photo),
        ),
      ),
    );
  }

  void showInSnackBar(String message) {
    _scaffoldKey.currentState
        .showSnackBar(new SnackBar(content: new Text(message)));
  }


  String timestamp() => new DateTime.now().millisecondsSinceEpoch.toString();

}
13
likes
15
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

Compress pictures taken with JPG quality

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on compressimage

Packages that implement compressimage