A simple flutter widget to paint with your fingers.
The widget supports:
- Changing fore- and background color
- Setting an image as background
- Changing the thickness of lines you draw
- Exporting your painting as png
- Undo/Redo drawing a line
- Clear the whole drawing
pubspec.yaml file within your Flutter Project:
dependencies: painter2: any
Then import it:
In order to use this plugin, first create a controller:
PainterController controller = PainterController(); controller.thickness = 5.0; // Set thickness of your brush. Defaults to 1.0 controller.backgroundColor = Colors.green; // Background color is ignores if you set a background image controller.backgroundImage = Image.network(...); // Sets a background image. You can load images as you would normally do: From an asset, from the network, from memory...
That controller will handle all properties of your drawing space.
Then, to display the painting area, create an inline
Painter object and give it a reference to your previously created controller:
By exporting the painting as PNG, you will get an Uint8List object which represents the bytes of the png final file:
The library does not handle saving the final image anywhere.
For a full example take a look at the example project. Here is a short recording showing it. Note that the color picker is an external dependency which is only required for the example.
- Built-in types and core primitives for a Flutter application. [...]
- Support for asynchronous programming, with classes such as Future and Stream. [...]
- Classes and utilities that supplement the collection support in dart:core. [...]
- Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
- Built-in types, collections, and other core functionality for every Dart program. [...]
- Interact with developer tools such as the debugger and inspector. [...]
- Mathematical constants and functions, plus a random number generator. [...]
- Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]
- File, socket, HTTP, and other I/O support for non-web applications. [...]
- Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]