Comments (2)
First, you need to update the path history class like this:-
class _PathHistory {
var redoPath = [];
List<MapEntry<Path, Paint>> _paths;
Paint currentPaint;
Paint _backgroundPaint;
bool _inDrag;
bool get isEmpty => _paths.isEmpty || (_paths.length == 1 && _inDrag);
_PathHistory()
: _paths = <MapEntry<Path, Paint>>[],
_inDrag = false,
_backgroundPaint = new Paint()..blendMode = BlendMode.dstOver,
currentPaint = new Paint()
..color = Colors.black
..strokeWidth = 1.0
..style = PaintingStyle.fill;
void setBackgroundColor(Color backgroundColor) {
_backgroundPaint.color = backgroundColor;
}
void undo() {
if (!_inDrag) {
if(_paths.isNotEmpty){
redoPath.add(_paths.last);
}
_paths.removeLast();
print("elements are ${redoPath.length}");
print("_paths elements are ${_paths.length}");
}
}
void redo(){
_paths.add(redoPath.last);
redoPath.removeLast();
print("redo path are ${redoPath.length}");
print("_paths elements are ${_paths.length}");
}
void clear() {
if (!_inDrag) {
_paths.clear();
redoPath.clear();
print("elements of undo ${_paths.length}");
print("elements of redo ${redoPath.length}");
}
}
void add(Offset startPoint) {
if (!_inDrag) {
_inDrag = true;
Path path = new Path();
path.moveTo(startPoint.dx, startPoint.dy);
_paths.add(new MapEntry<Path, Paint>(path, currentPaint));
}
}
void updateCurrent(Offset nextPoint) {
if (_inDrag) {
Path path = _paths.last.key;
path.lineTo(nextPoint.dx, nextPoint.dy);
}
}
void endCurrent() {
_inDrag = false;
}
void draw(Canvas canvas, Size size) {
canvas.saveLayer(Offset.zero & size, Paint());
for (MapEntry<Path, Paint> path in _paths) {
Paint p = path.value;
canvas.drawPath(path.key, p);
}
canvas.drawRect(
new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _backgroundPaint);
canvas.restore();
}
}
End Then Add This redo Methode In Painter controller like this:-
void redo(){
if (!isFinished()){
_pathHistory.redo();
notifyListeners();
}
}
you need to also update the undo method that I already do in path history's code
You're Welcome! :-)
from painter.
First, you need to update the path history class like this:-
class _PathHistory { var redoPath = []; List<MapEntry<Path, Paint>> _paths; Paint currentPaint; Paint _backgroundPaint; bool _inDrag; bool get isEmpty => _paths.isEmpty || (_paths.length == 1 && _inDrag); _PathHistory() : _paths = <MapEntry<Path, Paint>>[], _inDrag = false, _backgroundPaint = new Paint()..blendMode = BlendMode.dstOver, currentPaint = new Paint() ..color = Colors.black ..strokeWidth = 1.0 ..style = PaintingStyle.fill; void setBackgroundColor(Color backgroundColor) { _backgroundPaint.color = backgroundColor; } void undo() { if (!_inDrag) { if(_paths.isNotEmpty){ redoPath.add(_paths.last); } _paths.removeLast(); print("elements are ${redoPath.length}"); print("_paths elements are ${_paths.length}"); } } void redo(){ _paths.add(redoPath.last); redoPath.removeLast(); print("redo path are ${redoPath.length}"); print("_paths elements are ${_paths.length}"); } void clear() { if (!_inDrag) { _paths.clear(); redoPath.clear(); print("elements of undo ${_paths.length}"); print("elements of redo ${redoPath.length}"); } } void add(Offset startPoint) { if (!_inDrag) { _inDrag = true; Path path = new Path(); path.moveTo(startPoint.dx, startPoint.dy); _paths.add(new MapEntry<Path, Paint>(path, currentPaint)); } } void updateCurrent(Offset nextPoint) { if (_inDrag) { Path path = _paths.last.key; path.lineTo(nextPoint.dx, nextPoint.dy); } } void endCurrent() { _inDrag = false; } void draw(Canvas canvas, Size size) { canvas.saveLayer(Offset.zero & size, Paint()); for (MapEntry<Path, Paint> path in _paths) { Paint p = path.value; canvas.drawPath(path.key, p); } canvas.drawRect( new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _backgroundPaint); canvas.restore(); } }
End Then Add This redo Methode In Painter controller like this:-
void redo(){ if (!isFinished()){ _pathHistory.redo(); notifyListeners(); } }
you need to also update the undo method that I already do in path history's code
You're Welcome! :-)
Thank you so much!, I'm new in Flutter xD
from painter.
Related Issues (20)
- operation failed - throws when toImage() is called HOT 2
- Erase Mode Error Flutter Web HOT 2
- Flutter Painter class starts marking from wrong position when wrapping painter with InteractiveViewer
- Null safety HOT 5
- [BUG] Eraser and brush bug. HOT 1
- Support - Adding New custom shape using Custom paint on canvas. HOT 1
- Pinch to zoom capabilities HOT 4
- Permission to make a PR HOT 1
- Disable Multi-Touch | While moving two fingers on canvas painting gets destroyed. HOT 2
- How can I store the location of a path as a list of offsets? HOT 2
- Not able to re-assign PainterController HOT 3
- Erasing crashes app on mobile web HOT 1
- Don't get the full image (PNG) on mobile HOT 1
- exportAsPNGBytes reduce image quality
- Please provide the support for starting and ending point while user is drawing on the screen HOT 1
- Add a cap option
- Click a dot not working
- Can I record the drawing?
- Please add support to pass our own text
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from painter.