1
0
mirror of https://github.com/nisrulz/flutter-examples.git synced 2025-11-09 04:58:58 +00:00

Image Editor App (#75)

* added image editor

* package update
This commit is contained in:
Gourav Sarkar
2021-07-26 00:26:09 +05:30
committed by GitHub
parent abd78777a6
commit 48f14caf15
70 changed files with 1657 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
import 'package:photofilters/photofilters.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart';
import 'package:image/image.dart' as imageLib;
ApplyFilters(context,_image)async{
var image = imageLib.decodeImage(_image.readAsBytesSync());
image = imageLib.copyResize(image, width: 600);
String fileName=basename(_image.path);
Map imagefile = await Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new PhotoFilterSelector(
title: Text("Photo Filter Example"),
image: image,
appBarColor: Colors.greenAccent[400],
filters: presetFiltersList,
filename: fileName,
loader: Center(child: CircularProgressIndicator()),
fit: BoxFit.contain,
),
),
);
if (imagefile != null && imagefile.containsKey('image_filtered')) {
_image = imagefile['image_filtered'];
return _image;
}
else{
return null;
}
}

View File

@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:image_cropper/image_cropper.dart';
EditImg(_image)async{
var CroppedImg=await ImageCropper.cropImage(
sourcePath: _image.path,
aspectRatioPresets: [
CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2,
CropAspectRatioPreset.original,
CropAspectRatioPreset.ratio4x3,
CropAspectRatioPreset.ratio16x9
],
androidUiSettings: AndroidUiSettings(
toolbarTitle: 'Cropper',
activeControlsWidgetColor: Colors.greenAccent[400],
toolbarColor: Colors.greenAccent[400],
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false),
iosUiSettings: IOSUiSettings(
minimumAspectRatio: 1.0,
)
);
if(CroppedImg!=null){
_image=CroppedImg;
return _image;
}
else
return null;
}

View File

@@ -0,0 +1,15 @@
import 'package:image_picker/image_picker.dart';
import 'dart:io';
GetiImg(_image)async{
var pickedFile=await ImagePicker().getImage(source: ImageSource.gallery);
if(pickedFile!=null){
_image=File(pickedFile.path);
return _image;
}
else{
return null;
}
}

View File

@@ -0,0 +1,150 @@
import 'package:flutter/material.dart';
import 'package:image_editor/ApplyFilters.dart';
import 'package:image_editor/EditImg.dart';
import 'package:image_editor/GetImg.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_editor/SaveInGallery.dart';
import 'dart:io';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool _selected = false; //to check if a image is selected or not
File _image; //here we will store the selected image and apply modifications
double _ImageContainerHeight=450, _ImageContainerWidth=400;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.greenAccent[400],
title: Text('Flutter Image Editor'),
),
body: Container(
child: Column(
children: <Widget>[
Container(
height: _ImageContainerHeight,
width: _ImageContainerWidth,
child: _selected // checks if a image is selected or not
? Image.file(_image)
: Image.asset('images/cam.png')),
Row(
children: <Widget>[
Spacer(
flex: 2,
),
RaisedButton(
color: Colors.greenAccent[400],
child: Text(
'Get_Image', // to select a image from gallery
style: TextStyle(color: Colors.white),
),
onPressed: () async {
var _Ifile = await GetiImg(_image); // function called from GetImg.dart
if (_Ifile != null) {
setState(() {
_image = _Ifile;
_selected = true;
});
}
}),
Spacer(
flex: 1,
),
RaisedButton(
color: Colors.greenAccent[400],
child: Text(
'Edit Image', //to start editing the shape, size, etc of the selected image
style: TextStyle(color: Colors.white),
),
onPressed: () async {
if (_image != null) {
var _Ifile = await EditImg(_image); // function called from EditImg.dart
if (_Ifile != null) {
setState(() {
_image = _Ifile;
});
}
} else {
Fluttertoast.showToast(
msg: "Select a image first :-(",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0);
}
}),
Spacer(
flex: 2,
),
],
),
Row(
children: <Widget>[
Spacer(
flex: 2,
),
RaisedButton(
color: Colors.greenAccent[400],
child: Text(
'Apply Filters', //to start apply various photo filters to the selected image
style: TextStyle(color: Colors.white),
),
onPressed: () async {
if (_image != null) {
var _Ifile = await ApplyFilters(context, _image); // function called from ApplyFilters.dart
if (_Ifile != null) {
setState(() {
_image = _Ifile;
});
}
} else {
Fluttertoast.showToast(
msg: "Select a image first :-(",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0);
}
}),
Spacer(
flex: 1,
),
RaisedButton(
color: Colors.greenAccent[400],
child: Text(
'Download Editted image', //to save the edited image to gallery
style: TextStyle(color: Colors.white),
),
onPressed: () async {
if (_image != null) {
await SaveImg(_image); // function called from SaveInGallery.dart
} else {
Fluttertoast.showToast(
msg: "Select a image first :-(",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0);
}
}),
Spacer(
flex: 2,
),
],
),
],
)),
);
}
}

View File

@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:fluttertoast/fluttertoast.dart';
SaveImg(_image)async{
var result=await GallerySaver.saveImage(_image.path,albumName: 'ImageEditor').then((bool success) {
success?Fluttertoast.showToast(
msg:
"Image saved in gallery/ImageEditor",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green[400],
textColor: Colors.white,
fontSize: 16.0):
Fluttertoast.showToast(
msg:
"Something went wrong try again plz!!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green[400],
textColor: Colors.white,
fontSize: 16.0);
});
}

View File

@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
import 'package:image_editor/HomePage.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage()
);
}
}