Giter Site home page Giter Site logo

ep-u-nw / painter Goto Github PK

View Code? Open in Web Editor NEW
137.0 3.0 66.0 5.32 MB

A simple flutter widget to paint with your fingers

Home Page: https://pub.dev/packages/painter

License: Other

Swift 0.79% Objective-C 0.07% Dart 32.48% Kotlin 0.80% HTML 7.42% CMake 15.99% C++ 41.57% C 0.88%
flutter flutter-plugin dart

painter's Introduction

painter

A simple flutter widget to paint with your fingers.

Features

The widget supports:

  • Changing fore- and background color
  • Changing the thickness of lines you draw
  • Exporting your painting as png
  • Undo drawing a line
  • Clearing the whole drawing
  • Check if anything was drawn at all (using `PainterController.isEmpty')
  • Erase Mode

Some Notes

  • After calling 'finish()' on a PainterController you can't draw on this painting any more
  • To create a new painting after finishing the old one simply create a new PainterController
  • Calling 'finish()' for the first time will render the drawing. Successive calls will then return a cached version of the rendered picture

Example

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.

demo!

painter's People

Contributors

alongruss avatar epnw-eric avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

painter's Issues

Pinch to zoom capabilities

I am working on an App, where we want to draw with one finger and pinch to zoom with two fingers without pressing a button in between. Our problem is, that the drawing do not work properly, if we zoom in and try to draw because the image moves when drawing.
Are there any solutions for this problem?

Don't get the full image (PNG) on mobile

When i run the app on Web (Chrome) works like a charm (i make a signature, goes to the next step and at the end i made a base64 String with the data of the PNG (.toPNG()), but when i change to mobile the image don't render correctly (only do like 24 pixels of height) it does all the width (like 323 pixels).

Container with a button to generate the PNG and storage in a variable.
image

Button to print the base64 string
image

And this is the only result when i run the app in a mobile device (It's missing a lot of lines)
image

How it looks (the image have the correct dimensions but the content is missing):
image

[URGENT] making changes

Is is possible to make changes to the drawing stroke (eg: add new stroke, erase some stroke) after i am done with the drawing. For instance, i am done with the current drawing (in drawing screen), i navigate back to the home screen and i select the same drawing again to bring me back to the drawing screen, am i able to erase previously drawn stroke?

Multi touch bug

When I click with two fingers, I have a line draw.
It's possible to disable a multi touch functionality?

Erasing crashes app on mobile web

I noticed a crash when attempting to erase in my Flutter web application only on mobile web browsers. I then tested it with the example code from pub.dev and experienced the same behavior.

It appears that paint.blendMode = BlendMode.clear; is the culprit.

One quick workaround I found is to just simulate an erase stroke by painting using the backgroundColor.

if (_eraseMode) {
  paint.blendMode = BlendMode.srcOver;
  paint.color = backgroundColor;
}

However, in my app, my PainterController has backgroundColor = Colors.transparent.

I am not that familiar with different blend modes and if there is another way to achieve my desired result.

Suggestion : make getter method about _pathHistory in PaintController class.

I've tried to use this package in my app, and I think getter method about _pathHistory could be useful.
I used the package as sign pad, and I need a state of _path in the pathHistory class to get an information about sign pad's state whether sign pad is null or not.
So I added a few code in the PainterController class and _PathHistory class, like this :
in _PathHistory,
List<MapEntry<Path,Paint>> get paths => _paths;

in PainterController.
_PathHistory get pathHistory => _pathHistory;

This short codes enables me to make stop when there's no signature on the sign pad.
But it's uncomfortable to add this codes whenever I made new projects, so I suggest you to add this codes to original.

Flutter Painter class starts marking from wrong position when wrapping painter with InteractiveViewer

Im using painter package: https://pub.dev/packages/painter - painter: ^0.4.0 and default InteractiveViewer Widget

Painter class standalone is working fine but, when wrapping it with InteractiveViewer
InteractiveViewer(child: Painter(_controller))

on marking, it starts marking with delay, like approx. 10px from global position

I've tested my code by removing all other widgets, but the problem is still there.

Permission to make a PR

Hello,
I wanted to work on a feature and make PR, but I didn't have access to push to a new branch. Is there something else that I have to do?

access to image data while it is not finished

before I set the painter as finished I would like to:

  • know if anything has been painted at all (true/false)
  • get a snapshot image of the drawing but still let the user draw more
    is that possible?

Feature: thickness size based on speed

It would be cool have an option to enable the thickness of the pencil based on the speed of the cursor. I tried to draw something in native iOS and it seems to behave like that! What do you think?

operation failed - throws when toImage() is called

Hi
When we try to convert the painter to image/png it throws error saying "operation failed"
works in most of devices but facing issue in some iOS and some android devices[ tested in samsung s10 and honor devices]

any workaround or solution to get it fixed.

my logic is simple, pasting here....

try{
  var imgToSendBack =await _controller.finish().toPNG();
}catch(e){
print('save image catch error ${e.toString()}');
}

[BUG] Eraser and brush bug.

Once i use eraser, I can't go back to using brush. You can pick color, but the blendmode is still set to clear, and thus keeps erasing.

Null safety

Hey,
Do you guys plan to upgrade to support Dart Null Safety?

 dart pub outdated --mode=null-safety
Resolving...
Showing dependencies that are currently not opted in to null-safety.
[✗] indicates versions without null safety support.
[✓] indicates versions opting in to null safety.   

Computing null safety support...
Package Name                          Current        Upgradable      Resolvable  Latest

direct dependencies:
...
painter                               ✗0.4.0         ✗0.4.0          -           ✗0.4.0
...

Method of further modifying a picture after it has been finished

When finish() is called on the PaintController for the first time, a Picture is rendered from the paths. Any later calls to finish() will return that same Picture, which was cached by the first call to finish(). So, any changes made (such as new paths added) after the first call to finish() will be left out of the output Picture.

It would be very useful to be able to make changes, output the Picture (for example to save to disk as a bitmap), then be able to make further changes and output the picture again, with these new changes.

As far as I can tell there's currently no way to do this? If that's the case, it would be a very welcome addition. Thank you!

Change size to drawable section

Hi @EPNW,

I need to draw on an image. So the drawable section should be the size of that image. Is it possible to indicate the size of the Painter that you want to use?

Not able to re-assign PainterController

I want to re-assign PainterController object but it throws me A PainterController was used after being disposed.

My Scenario

I want to make a painter screen similar to the one of Social Media apps like instagram or fb messenger. So, the user can draw something on the image, but he/she can also update it in a second moment.

I have two screen ImageScreen and BrushScreen. in the ImageScreen there is option to go for Brush and draw anything on image. then user can tap "Done" button and get back to ImageScreen. But when user again go to the BrushScreen i need to keep PainterController. So user can update with existing one.

It works when assigned PainterController first time. but at second time it throws error as i mentioned above.

Any help on this would be much appreciated!

Code Snippet

BrushScreen

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:painter/painter.dart';

class BrushScreen extends StatefulWidget {
  final File imageFile;

  const BrushScreen({Key? key, required this.imageFile}) : super(key: key);

  @override
  _BrushScreenState createState() => _BrushScreenState();
}

class _BrushScreenState extends State<BrushScreen> {
  late final PainterController _controller;

  @override
  void initState() {
    super.initState();
    _controller = PainterController()
      ..backgroundColor = Colors.transparent
      ..drawColor = Colors.white;

    _controller.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: SafeArea(
        child: Column(
          children: [
            Expanded(
              child: Stack(
                children: [
                  Positioned.fill(
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(16),
                      child: Image.file(
                        widget.imageFile,
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
                  Painter(_controller),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}

ImageScreen Brush button

onTap: () async {
  final result = await Navigator.of(context).push(MaterialPageRoute(builder: (_) => 
  BrushScreen(imageFile: imageFile)));
  if (result is PainterController)
                      setState(() {
                        _paintController = result;
                      });
                  },

Add a cap option

Could you create an option to set the cap of the lines to circular etc..?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.