image_overlay_editor 1.0.1
image_overlay_editor: ^1.0.1 copied to clipboard
A production-ready Flutter package for creating image editors with overlay functionality. Perfect for apps that need to add stickers, text, or other images on top of photos and upload the result to cl [...]
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:image_overlay_editor/image_overlay_editor.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Image Editor Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Image Editor Demo')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Image Overlay Editor',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
const Text(
'Tap the button below to try the image editor',
style: TextStyle(fontSize: 16, color: Colors.grey),
textAlign: TextAlign.center,
),
const SizedBox(height: 40),
ElevatedButton(
onPressed: () => _openEditor(context),
child: const Text('Open Image Editor'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16),
),
),
],
),
),
),
);
}
void _openEditor(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImageEditor(
networkImages: [
"https://picsum.photos/200/200?random=1",
"https://picsum.photos/200/200?random=2",
"https://picsum.photos/200/200?random=3",
],
onSave: (File editedImage) {
uploadToCloudStorage(editedImage);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Image ready for upload!'),
backgroundColor: Colors.green,
action: SnackBarAction(
label: 'Upload',
onPressed: () => uploadToCloudStorage(editedImage),
),
),
);
},
onError: (error) {
_showErrorSnackBar(context, error);
},
),
),
);
}
void _showErrorSnackBar(BuildContext context, String error) {
String errorMessage = error;
if (error.contains('Permission denied') || error.contains('access denied')) {
errorMessage = 'Permission denied. Please grant camera and photo library permissions in your device settings.';
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(errorMessage),
backgroundColor: Colors.red,
duration: const Duration(seconds: 5),
action: SnackBarAction(
label: 'Settings',
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Please go to Settings > Privacy & Security > Photos/Camera and enable access for this app.'),
duration: Duration(seconds: 3),
),
);
},
),
),
);
}
void uploadToCloudStorage(File imageFile) {
Future.delayed(const Duration(seconds: 2), () {
// Upload completed
});
}
}