simple_painter 1.0.0 simple_painter: ^1.0.0 copied to clipboard
A Flutter widget that enables drawing, adding text, shapes, and images on a customizable background with layer management, undo/redo functionality, and interactive item styling.
Painter Widget #
Flutter Painter is a Flutter package that lets users create and manipulate a drawing canvas with layers. It supports adding and styling text, images, and shapes, along with freehand drawing tools, customizable brush sizes, and colors. The package also includes undo/redo functionality and custom background support.
Features #
-
Drawing Tools
- Freehand drawing with customizable brush size and color.
- Eraser tool for removing strokes.
-
State Management
- Undo and redo functionality for actions.
- Export final design as an image.
-
Interactive Elements
- Add, move, resize, rotate, and delete text, images, or shapes.
- Edit styles of added elements, such as font size, color, or shape properties.
- Layer-based organization of elements.
-
Custom Background
- Load custom images as the background.
- Preserve aspect ratio for responsive designs.
Installation #
To start using Painter Widget, add it to your project's pubspec.yaml
file:
dependencies:
simple_painter: ^1.0.0
Then, run the following command in your terminal:
flutter pub get
Getting Started #
- Import the package in your Dart file:
import 'package:painter_widget/simple_painter.dart';
- Create a
PainterController
to manage the drawing and interactions:
final PainterController controller = PainterController();
- Add the
PainterWidget
to your widget tree:
PainterWidget(controller: controller);
Usage Examples #
Basic Implementation #
Here’s how to set up a basic painting widget with a simple controller:
import 'package:flutter/material.dart';
import 'package:painter_widget/simple_painter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final controller = PainterController();
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Painter Widget Example')),
body: PainterWidget(controller: controller),
),
);
}
}
Drawing and Erasing #
Enable drawing and erasing with these configurations:
controller.toggleDrawing();; // Enable freehand drawing
controller.changeBrushValues( // Edit brush options
size: 15
color: Color(0xFFFFFF),
;
controller.toggleErasing(); // Enable eraser mode
Adding Interactive Items #
Add text, shapes, or images dynamically:
await controller.addText(text); // Add text item
controller.changeTextValues( // Change text style
item,
textStyle: TextStyle(),
textAlign: TextAlign.center,
enableGradientColor: false,
...
)
controller.addImageUint8List(imageUint8List); // Add image item
controller.changeImageValues( // Change image style
item,
boxFit: BoxFit.fill,
borderRadius: BorderRadius.circular(intValue.toDouble()),
borderColr: Color(0xFFFFFF),
...
)
Custom Background Image #
Set a background image while maintaining aspect ratio:
await controller.setBackgroundImage(imageUint8List);
// or
controller = PainterController(
backgroundImage: imageUint8List,
);
NOTE: For more detailed information and to test features like layer management, state handling, and element styling, please visit the Painter Full Stack Example.
Contributing #
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-name
). - Commit your changes (
git commit -m 'Add feature'
). - Push to your branch (
git push origin feature-name
). - Open a pull request.
License #
This package is distributed under the MIT License. See LICENSE for more information.