Created
May 15, 2019 20:24
-
-
Save btastic/1f18997592870c0aa5dd27a3d48b35a4 to your computer and use it in GitHub Desktop.
Repro flutter_native_image repro 47
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:flutter/material.dart'; | |
import 'package:image_picker/image_picker.dart'; | |
import 'package:flutter_native_image/flutter_native_image.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _counter = 0; | |
Future _getImageGallery() async { | |
File imageFile = await ImagePicker.pickImage(source: ImageSource.gallery); | |
FocusScope.of(context).requestFocus(new FocusNode()); | |
if (imageFile != null) { | |
await imageUpload(imageFile); | |
} | |
} | |
imageUpload(imageFile) async { | |
ImageProperties properties = | |
await FlutterNativeImage.getImageProperties(imageFile.path); | |
File compressedFile = await FlutterNativeImage.compressImage( | |
imageFile.path, | |
quality: 10, | |
targetWidth: 300, | |
targetHeight: | |
(properties.height * 300 / properties.width).round()); | |
String fileName = DateTime.now().millisecondsSinceEpoch.toString() + '.jpg'; | |
// compressedFile.path is set, so compressing worked.. | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'$_counter', | |
style: Theme.of(context).textTheme.display1, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () async => await _getImageGallery(), | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment