p5 0.0.4

  • README.md
  • Installing
  • Versions
  • 24

p5.dart #

A Dart implementation of the Processing API for Flutter. Processing is a software sketchbook and a language for learning how to code within the context of the visual arts.

Getting Started #

Add the p5 package to your Flutter app. For help using packages, see Flutter's online documentation.

You need to implement the widget containing the Processing sketch, and the sketch itself.

A simple widget tree is the follwing:

import 'package:flutter/material.dart';

import "package:p5/p5.dart";
import "sketch.dart";

void main() => runApp(new MyApp());

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  _MyHomePageState createState() {
    return new _MyHomePageState();

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'P5 Demo',
      theme: new ThemeData(
        // This is the theme of your application.
        primarySwatch: Colors.blue,
      home: new MyHomePage(title: 'P5 Demo Home Page'),

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  MySketch sketch;
  PAnimator animator;

  void initState() {
    sketch = new MySketch();
    // Need an animator to call the draw() method in the sketch continuously,
    // otherwise it will be called only when touch events are detected.
    animator = new PAnimator(this);
    animator.addListener(() {
      setState(() {

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text("P5 Draw!")),
      backgroundColor: const Color.fromRGBO(200, 200, 200, 1.0),
      body: new Center(
        child:new PWidget(sketch),

The MySketch class has to extend the base PPainter clas in the p5 package, and implement the setup() and draw() functions:

class MySketch extends PPainter {
  void setup() {
    size(300, 300);

  void draw() {
    background(color(255, 255, 255));

Both pieces of code can be inside single dart file, or on separate files for better clarity.

A simple drawing sketch can be implemented by handling the mouse dragging, and storing the pointer positions in a list of PVector object holding the (x, y) coordinates, which are then used to draw lines:

class MySketch extends PPainter {
  var strokes = new List<List<PVector>>();

  void setup() {

  void draw() {
    background(color(255, 255, 255));

    stroke(color(10, 40, 200, 60));
    for (var stroke in strokes) {
      for (var p in stroke) {
        vertex(p.x, p.y);

  void mousePressed() {
    strokes.add([new PVector(mouseX, mouseY)]);

  void mouseDragged() {
    var stroke = strokes.last;
    stroke.add(new PVector(mouseX, mouseY));

Notice that the size of the drawing area can be made to fill the entire app by using fullScreen(). The app should give similar results for both iOS and Android:

P5 drawing sketch running in iPhone 6S and Nexus 5X

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

[0.0.4] - July 24, 2018.

  • Correctly implemented polygon rendering using Path.drawPolygon()

[0.0.3] - July 21, 2018.

  • Implemented translate, rotate, scale, push, and pop
  • Reimplemented shapes, not yet working as expected
  • Put constants inside a PConstant class

[0.0.2] - July 2, 2018.

  • Updated environment

[0.0.1] - June 26, 2018.

  • First release with a few Processing API functions in PPainter.
  • PAnimator utility class to drive continuous frama animation.
  • Basic touch event handling

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  p5: ^0.0.4

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:p5/p5.dart';
Version Uploaded Documentation Archive
0.0.5 Feb 22, 2019 Go to the documentation of p5 0.0.5 Download p5 0.0.5 archive
0.0.4 Jul 24, 2018 Go to the documentation of p5 0.0.4 Download p5 0.0.4 archive
0.0.3 Jul 21, 2018 Go to the documentation of p5 0.0.3 Download p5 0.0.3 archive
0.0.2 Jun 26, 2018 Go to the documentation of p5 0.0.2 Download p5 0.0.2 archive
0.0.1 Jun 26, 2018 Go to the documentation of p5 0.0.1 Download p5 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0