mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-24 16:50:47 +00:00
Convert 17 multi-file apps to the validated pattern: lib/main.dart keeps only the MaterialApp bootstrap; a new lib/example.dart holds the full entry screen and focused example code, importing existing supporting files (screens/, tabs/, services/, models/, widgets/, utils/). Apps: analytics_integration, animation_example, biometrics, bottom_sheet, custom_home_drawer, google_signin, grid_layout, handling_routes, image_editor, scan_qr_code, statless_counter_app, using_bottom_nav_bar, using_custom_fonts, using_listview, using_listwheelscrollview, using_platform_adaptive, view_pdf_file
130 lines
4.4 KiB
Dart
130 lines
4.4 KiB
Dart
// Example: Image editor screen
|
|
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:image_editor/SaveInGallery.dart';
|
|
import 'dart:io';
|
|
|
|
class Example extends StatefulWidget {
|
|
const Example({super.key});
|
|
|
|
@override
|
|
_ExampleState createState() => _ExampleState();
|
|
}
|
|
|
|
class _ExampleState extends State<Example> {
|
|
bool _selected = false; //to check if a image is selected or not
|
|
late File
|
|
_image; //here we will store the selected image and apply modifications
|
|
final double _ImageContainerHeight = 450;
|
|
final double _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>[
|
|
SizedBox(
|
|
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,
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: 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,
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: 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 {
|
|
var Ifile0 = await EditImg(
|
|
_image); // function called from EditImg.dart
|
|
if (Ifile0 != null) {
|
|
setState(() {
|
|
_image = Ifile0;
|
|
});
|
|
}
|
|
}),
|
|
Spacer(
|
|
flex: 2,
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
children: <Widget>[
|
|
Spacer(
|
|
flex: 2,
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.greenAccent[400]),
|
|
child: Text(
|
|
'Apply Filters', //to start apply various photo filters to the selected image
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
onPressed: () async {
|
|
var Ifile0 = await ApplyFilters(context,
|
|
_image); // function called from ApplyFilters.dart
|
|
if (Ifile0 != null) {
|
|
setState(() {
|
|
_image = Ifile0;
|
|
});
|
|
}
|
|
}),
|
|
Spacer(
|
|
flex: 1,
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.greenAccent[400]),
|
|
child: Text(
|
|
'Download Editted image', //to save the edited image to gallery
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
onPressed: () async {
|
|
await SaveImg(
|
|
_image); // function called from SaveInGallery.dart
|
|
}),
|
|
Spacer(
|
|
flex: 2,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
)),
|
|
);
|
|
}
|
|
}
|