Flutter:- paint using Float32Int and drawRawPoints












2















I am trying to paint using Float32Int and drawRawPoints but, it's showing that
bad state element.
I have created one list type of Float32Int and in Float32Int var, and then I am storing offset on by on in the list. in paint method using for loop, I am trying to paint. but it shwoing bad state of element in the console



library painter;

import 'package:flutter/widgets.dart' hide Image;
import 'dart:ui';
import 'dart:async';
import 'dart:typed_data';

class Painter extends StatefulWidget {
final PainterController painterController;

Painter(PainterController painterController)
: this.painterController = painterController,
super(key: new ValueKey<PainterController>(painterController));

@override
_PainterState createState() => new _PainterState();
}

class _PainterState extends State<Painter> {
bool _finished;

@override
void initState() {
super.initState();
_finished = false;
widget.painterController._widgetFinish = _finish;
}

Size _finish() {
setState(() {
_finished = true;
});
return context.size;
}

@override
Widget build(BuildContext context) {
Widget child = new CustomPaint(
willChange: true,
painter: new _PainterPainter(widget.painterController._pathHistory,
repaint: widget.painterController),
);
child = new ClipRect(child: child);
if (!_finished) {
child = new GestureDetector(
child: child,
onPanStart: _onPanStart,
onPanUpdate: _onPanUpdate,
onPanEnd: _onPanEnd,
);
}
return new Container(
child: child,
width: double.infinity,
height: double.infinity,
);
}

void _onPanStart(DragStartDetails start) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(start.globalPosition);
widget.painterController._pathHistory.add(pos);
widget.painterController._notifyListeners();
}

void _onPanUpdate(DragUpdateDetails update) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(update.globalPosition);
widget.painterController._pathHistory.updateCurrent(pos);
widget.painterController._notifyListeners();
}

void _onPanEnd(DragEndDetails end) {
widget.painterController._pathHistory.endCurrent();
widget.painterController._notifyListeners();
}
}

class _PainterPainter extends CustomPainter {
final _PathHistory _path;

_PainterPainter(this._path, {Listenable repaint}) : super(repaint: repaint);

@override
void paint(Canvas canvas, Size size) {
_path.draw(canvas, size);
}

@override
bool shouldRepaint(_PainterPainter oldDelegate) {
return true;
}
}

class _PathHistory {
List<MapEntry<Path, Paint>> _paths;
Paint currentPaint;
Paint _backgroundPaint;
bool _inDrag;

_PathHistory() {
_paths = new List<MapEntry<Path, Paint>>();
_inDrag = false;
_backgroundPaint = new Paint();
}

void setBackgroundColor(Color backgroundColor) {
_backgroundPaint.color = backgroundColor;
}

void undo() {
if (!_inDrag) {
_paths.removeLast();
}
}

void clear() {
if (!_inDrag) {
_paths.clear();
}
}

static List<Float32List> list = ;

Float32List float32list;
// Float32List floatPoints = Float32List.fromList(list);
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));
float32list.addAll([startPoint.dx, startPoint.dy]);
}
}

void updateCurrent(Offset nextPoint) {
if (_inDrag) {
// path.lineTo(nextPoint.dx, nextPoint.dy);
float32list.addAll([nextPoint.dx, nextPoint.dy]);
}
}

void endCurrent() {
_inDrag = false;
list.add(float32list);
}

void draw(Canvas canvas, Size size) {
Paint p = new Paint();
p.strokeCap = StrokeCap.round;
p.strokeWidth = 20.0;
canvas.drawRect(
new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _backgroundPaint);

for (int i = 0; i < list.length; i++) {
if (list.isNotEmpty) canvas.drawRawPoints(PointMode.lines, list[i], p);
}
}
}

typedef PictureDetails PictureCallback();

class PictureDetails {
final Picture picture;
final int width;
final int height;

const PictureDetails(this.picture, this.width, this.height);

Image toImage() {
return picture.toImage(width, height);
}

Future<Uint8List> toPNG() async {
return (await toImage().toByteData(format: ImageByteFormat.png))
.buffer
.asUint8List();
}
}

class PainterController extends ChangeNotifier {
Color _drawColor = new Color.fromARGB(255, 0, 0, 0);
Color _backgroundColor = new Color.fromARGB(255, 255, 255, 255);

double _thickness = 1.0;
PictureDetails _cached;
_PathHistory _pathHistory;
ValueGetter<Size> _widgetFinish;

PainterController() {
_pathHistory = new _PathHistory();
}

Color get drawColor => _drawColor;
set drawColor(Color color) {
_drawColor = color;
_updatePaint();
}

Color get backgroundColor => _backgroundColor;
set backgroundColor(Color color) {
_backgroundColor = color;
_updatePaint();
}

double get thickness => _thickness;
set thickness(double t) {
_thickness = t;
_updatePaint();
}

void _updatePaint() {
Paint paint = new Paint();
paint.color = drawColor;
paint.style = PaintingStyle.stroke;
paint.strokeWidth = thickness;
_pathHistory.currentPaint = paint;
_pathHistory.setBackgroundColor(backgroundColor);
notifyListeners();
}

void undo() {
if (!isFinished()) {
_pathHistory.undo();
notifyListeners();
}
}

void _notifyListeners() {
notifyListeners();
}

void clear() {
if (!isFinished()) {
_pathHistory.clear();
notifyListeners();
}
}

PictureDetails finish() {
if (!isFinished()) {
_cached = _render(_widgetFinish());
}
return _cached;
}

PictureDetails _render(Size size) {
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder);
_pathHistory.draw(canvas, size);
return new PictureDetails(
recorder.endRecording(), size.width.floor(), size.height.floor());
}

bool isFinished() {
return _cached != null;
}
}




══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (17993): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter (17993): The method 'addAll' was called on null.
I/flutter (17993): Receiver: null
I/flutter (17993): Tried calling: addAll(Instance(length:2) of '_GrowableList')
I/flutter (17993):
I/flutter (17993): When the exception was thrown, this was the stack:
I/flutter (17993): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (17993): #1 _PathHistory.add (package:painter/painter.dart:133:19)
I/flutter (17993): #2 _PainterState._onPanStart (package:painter/painter.dart:62:43)
I/flutter (17993): #3 DragGestureRecognizer.acceptGesture.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:169:47)
I/flutter (17993): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
I/flutter (17993): #5 DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:169:9)
I/flutter (17993): #6 GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:250:25)
I/flutter (17993): #7 GestureArenaManager._tryToResolveArena.<anonymous closure> (package:flutter/src/gestures/arena.dart:231:31)
I/flutter (17993): (elided 2 frames from package dart:async)
I/flutter (17993):
I/flutter (17993): Handler: onStart
I/flutter (17993): Recognizer:
I/flutter (17993): PanGestureRecognizer#80c77(debugOwner: GestureDetector)
I/flutter (17993): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.


Stack Trace:



[ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (11464): oh no!
E/flutter (11464): package:painter/painter.dart 39:5 _PainterState.runAsync
E/flutter (11464): package:painter/painter.dart 35:62 _PainterState.scheduleAsync.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:26 StackZoneSpecification._registerUnaryCallback.<fn>.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:14 StackZoneSpecification._registerUnaryCallback.<fn>
E/flutter (11464): dart:async/zone.dart 1132:38 _rootRunUnary
E/flutter (11464): dart:async/zone.dart 1029:19 _CustomZone.runUnary
E/flutter (11464): dart:async/future_impl.dart 129:18 _FutureListener.handleValue
E/flutter (11464): dart:async/future_impl.dart 642:45 Future._propagateToListeners.handleValueCallback
E/flutter (11464): dart:async/future_impl.dart 671:32 Future._propagateToListeners
E/flutter (11464): dart:async/future_impl.dart 476:7 Future._complete
E/flutter (11464): dart:async/future.dart 316:16 new Future.delayed.<fn> E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback.<fn>









share|improve this question

























  • post 4-6 top frames from the stacktrace

    – pskink
    Nov 24 '18 at 7:07











  • Whatever I am getting the error in console, I added at end of my code.

    – satish
    Nov 26 '18 at 6:05











  • in the end, the stack is also given.

    – satish
    Nov 26 '18 at 6:13
















2















I am trying to paint using Float32Int and drawRawPoints but, it's showing that
bad state element.
I have created one list type of Float32Int and in Float32Int var, and then I am storing offset on by on in the list. in paint method using for loop, I am trying to paint. but it shwoing bad state of element in the console



library painter;

import 'package:flutter/widgets.dart' hide Image;
import 'dart:ui';
import 'dart:async';
import 'dart:typed_data';

class Painter extends StatefulWidget {
final PainterController painterController;

Painter(PainterController painterController)
: this.painterController = painterController,
super(key: new ValueKey<PainterController>(painterController));

@override
_PainterState createState() => new _PainterState();
}

class _PainterState extends State<Painter> {
bool _finished;

@override
void initState() {
super.initState();
_finished = false;
widget.painterController._widgetFinish = _finish;
}

Size _finish() {
setState(() {
_finished = true;
});
return context.size;
}

@override
Widget build(BuildContext context) {
Widget child = new CustomPaint(
willChange: true,
painter: new _PainterPainter(widget.painterController._pathHistory,
repaint: widget.painterController),
);
child = new ClipRect(child: child);
if (!_finished) {
child = new GestureDetector(
child: child,
onPanStart: _onPanStart,
onPanUpdate: _onPanUpdate,
onPanEnd: _onPanEnd,
);
}
return new Container(
child: child,
width: double.infinity,
height: double.infinity,
);
}

void _onPanStart(DragStartDetails start) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(start.globalPosition);
widget.painterController._pathHistory.add(pos);
widget.painterController._notifyListeners();
}

void _onPanUpdate(DragUpdateDetails update) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(update.globalPosition);
widget.painterController._pathHistory.updateCurrent(pos);
widget.painterController._notifyListeners();
}

void _onPanEnd(DragEndDetails end) {
widget.painterController._pathHistory.endCurrent();
widget.painterController._notifyListeners();
}
}

class _PainterPainter extends CustomPainter {
final _PathHistory _path;

_PainterPainter(this._path, {Listenable repaint}) : super(repaint: repaint);

@override
void paint(Canvas canvas, Size size) {
_path.draw(canvas, size);
}

@override
bool shouldRepaint(_PainterPainter oldDelegate) {
return true;
}
}

class _PathHistory {
List<MapEntry<Path, Paint>> _paths;
Paint currentPaint;
Paint _backgroundPaint;
bool _inDrag;

_PathHistory() {
_paths = new List<MapEntry<Path, Paint>>();
_inDrag = false;
_backgroundPaint = new Paint();
}

void setBackgroundColor(Color backgroundColor) {
_backgroundPaint.color = backgroundColor;
}

void undo() {
if (!_inDrag) {
_paths.removeLast();
}
}

void clear() {
if (!_inDrag) {
_paths.clear();
}
}

static List<Float32List> list = ;

Float32List float32list;
// Float32List floatPoints = Float32List.fromList(list);
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));
float32list.addAll([startPoint.dx, startPoint.dy]);
}
}

void updateCurrent(Offset nextPoint) {
if (_inDrag) {
// path.lineTo(nextPoint.dx, nextPoint.dy);
float32list.addAll([nextPoint.dx, nextPoint.dy]);
}
}

void endCurrent() {
_inDrag = false;
list.add(float32list);
}

void draw(Canvas canvas, Size size) {
Paint p = new Paint();
p.strokeCap = StrokeCap.round;
p.strokeWidth = 20.0;
canvas.drawRect(
new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _backgroundPaint);

for (int i = 0; i < list.length; i++) {
if (list.isNotEmpty) canvas.drawRawPoints(PointMode.lines, list[i], p);
}
}
}

typedef PictureDetails PictureCallback();

class PictureDetails {
final Picture picture;
final int width;
final int height;

const PictureDetails(this.picture, this.width, this.height);

Image toImage() {
return picture.toImage(width, height);
}

Future<Uint8List> toPNG() async {
return (await toImage().toByteData(format: ImageByteFormat.png))
.buffer
.asUint8List();
}
}

class PainterController extends ChangeNotifier {
Color _drawColor = new Color.fromARGB(255, 0, 0, 0);
Color _backgroundColor = new Color.fromARGB(255, 255, 255, 255);

double _thickness = 1.0;
PictureDetails _cached;
_PathHistory _pathHistory;
ValueGetter<Size> _widgetFinish;

PainterController() {
_pathHistory = new _PathHistory();
}

Color get drawColor => _drawColor;
set drawColor(Color color) {
_drawColor = color;
_updatePaint();
}

Color get backgroundColor => _backgroundColor;
set backgroundColor(Color color) {
_backgroundColor = color;
_updatePaint();
}

double get thickness => _thickness;
set thickness(double t) {
_thickness = t;
_updatePaint();
}

void _updatePaint() {
Paint paint = new Paint();
paint.color = drawColor;
paint.style = PaintingStyle.stroke;
paint.strokeWidth = thickness;
_pathHistory.currentPaint = paint;
_pathHistory.setBackgroundColor(backgroundColor);
notifyListeners();
}

void undo() {
if (!isFinished()) {
_pathHistory.undo();
notifyListeners();
}
}

void _notifyListeners() {
notifyListeners();
}

void clear() {
if (!isFinished()) {
_pathHistory.clear();
notifyListeners();
}
}

PictureDetails finish() {
if (!isFinished()) {
_cached = _render(_widgetFinish());
}
return _cached;
}

PictureDetails _render(Size size) {
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder);
_pathHistory.draw(canvas, size);
return new PictureDetails(
recorder.endRecording(), size.width.floor(), size.height.floor());
}

bool isFinished() {
return _cached != null;
}
}




══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (17993): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter (17993): The method 'addAll' was called on null.
I/flutter (17993): Receiver: null
I/flutter (17993): Tried calling: addAll(Instance(length:2) of '_GrowableList')
I/flutter (17993):
I/flutter (17993): When the exception was thrown, this was the stack:
I/flutter (17993): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (17993): #1 _PathHistory.add (package:painter/painter.dart:133:19)
I/flutter (17993): #2 _PainterState._onPanStart (package:painter/painter.dart:62:43)
I/flutter (17993): #3 DragGestureRecognizer.acceptGesture.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:169:47)
I/flutter (17993): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
I/flutter (17993): #5 DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:169:9)
I/flutter (17993): #6 GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:250:25)
I/flutter (17993): #7 GestureArenaManager._tryToResolveArena.<anonymous closure> (package:flutter/src/gestures/arena.dart:231:31)
I/flutter (17993): (elided 2 frames from package dart:async)
I/flutter (17993):
I/flutter (17993): Handler: onStart
I/flutter (17993): Recognizer:
I/flutter (17993): PanGestureRecognizer#80c77(debugOwner: GestureDetector)
I/flutter (17993): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.


Stack Trace:



[ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (11464): oh no!
E/flutter (11464): package:painter/painter.dart 39:5 _PainterState.runAsync
E/flutter (11464): package:painter/painter.dart 35:62 _PainterState.scheduleAsync.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:26 StackZoneSpecification._registerUnaryCallback.<fn>.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:14 StackZoneSpecification._registerUnaryCallback.<fn>
E/flutter (11464): dart:async/zone.dart 1132:38 _rootRunUnary
E/flutter (11464): dart:async/zone.dart 1029:19 _CustomZone.runUnary
E/flutter (11464): dart:async/future_impl.dart 129:18 _FutureListener.handleValue
E/flutter (11464): dart:async/future_impl.dart 642:45 Future._propagateToListeners.handleValueCallback
E/flutter (11464): dart:async/future_impl.dart 671:32 Future._propagateToListeners
E/flutter (11464): dart:async/future_impl.dart 476:7 Future._complete
E/flutter (11464): dart:async/future.dart 316:16 new Future.delayed.<fn> E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback.<fn>









share|improve this question

























  • post 4-6 top frames from the stacktrace

    – pskink
    Nov 24 '18 at 7:07











  • Whatever I am getting the error in console, I added at end of my code.

    – satish
    Nov 26 '18 at 6:05











  • in the end, the stack is also given.

    – satish
    Nov 26 '18 at 6:13














2












2








2








I am trying to paint using Float32Int and drawRawPoints but, it's showing that
bad state element.
I have created one list type of Float32Int and in Float32Int var, and then I am storing offset on by on in the list. in paint method using for loop, I am trying to paint. but it shwoing bad state of element in the console



library painter;

import 'package:flutter/widgets.dart' hide Image;
import 'dart:ui';
import 'dart:async';
import 'dart:typed_data';

class Painter extends StatefulWidget {
final PainterController painterController;

Painter(PainterController painterController)
: this.painterController = painterController,
super(key: new ValueKey<PainterController>(painterController));

@override
_PainterState createState() => new _PainterState();
}

class _PainterState extends State<Painter> {
bool _finished;

@override
void initState() {
super.initState();
_finished = false;
widget.painterController._widgetFinish = _finish;
}

Size _finish() {
setState(() {
_finished = true;
});
return context.size;
}

@override
Widget build(BuildContext context) {
Widget child = new CustomPaint(
willChange: true,
painter: new _PainterPainter(widget.painterController._pathHistory,
repaint: widget.painterController),
);
child = new ClipRect(child: child);
if (!_finished) {
child = new GestureDetector(
child: child,
onPanStart: _onPanStart,
onPanUpdate: _onPanUpdate,
onPanEnd: _onPanEnd,
);
}
return new Container(
child: child,
width: double.infinity,
height: double.infinity,
);
}

void _onPanStart(DragStartDetails start) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(start.globalPosition);
widget.painterController._pathHistory.add(pos);
widget.painterController._notifyListeners();
}

void _onPanUpdate(DragUpdateDetails update) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(update.globalPosition);
widget.painterController._pathHistory.updateCurrent(pos);
widget.painterController._notifyListeners();
}

void _onPanEnd(DragEndDetails end) {
widget.painterController._pathHistory.endCurrent();
widget.painterController._notifyListeners();
}
}

class _PainterPainter extends CustomPainter {
final _PathHistory _path;

_PainterPainter(this._path, {Listenable repaint}) : super(repaint: repaint);

@override
void paint(Canvas canvas, Size size) {
_path.draw(canvas, size);
}

@override
bool shouldRepaint(_PainterPainter oldDelegate) {
return true;
}
}

class _PathHistory {
List<MapEntry<Path, Paint>> _paths;
Paint currentPaint;
Paint _backgroundPaint;
bool _inDrag;

_PathHistory() {
_paths = new List<MapEntry<Path, Paint>>();
_inDrag = false;
_backgroundPaint = new Paint();
}

void setBackgroundColor(Color backgroundColor) {
_backgroundPaint.color = backgroundColor;
}

void undo() {
if (!_inDrag) {
_paths.removeLast();
}
}

void clear() {
if (!_inDrag) {
_paths.clear();
}
}

static List<Float32List> list = ;

Float32List float32list;
// Float32List floatPoints = Float32List.fromList(list);
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));
float32list.addAll([startPoint.dx, startPoint.dy]);
}
}

void updateCurrent(Offset nextPoint) {
if (_inDrag) {
// path.lineTo(nextPoint.dx, nextPoint.dy);
float32list.addAll([nextPoint.dx, nextPoint.dy]);
}
}

void endCurrent() {
_inDrag = false;
list.add(float32list);
}

void draw(Canvas canvas, Size size) {
Paint p = new Paint();
p.strokeCap = StrokeCap.round;
p.strokeWidth = 20.0;
canvas.drawRect(
new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _backgroundPaint);

for (int i = 0; i < list.length; i++) {
if (list.isNotEmpty) canvas.drawRawPoints(PointMode.lines, list[i], p);
}
}
}

typedef PictureDetails PictureCallback();

class PictureDetails {
final Picture picture;
final int width;
final int height;

const PictureDetails(this.picture, this.width, this.height);

Image toImage() {
return picture.toImage(width, height);
}

Future<Uint8List> toPNG() async {
return (await toImage().toByteData(format: ImageByteFormat.png))
.buffer
.asUint8List();
}
}

class PainterController extends ChangeNotifier {
Color _drawColor = new Color.fromARGB(255, 0, 0, 0);
Color _backgroundColor = new Color.fromARGB(255, 255, 255, 255);

double _thickness = 1.0;
PictureDetails _cached;
_PathHistory _pathHistory;
ValueGetter<Size> _widgetFinish;

PainterController() {
_pathHistory = new _PathHistory();
}

Color get drawColor => _drawColor;
set drawColor(Color color) {
_drawColor = color;
_updatePaint();
}

Color get backgroundColor => _backgroundColor;
set backgroundColor(Color color) {
_backgroundColor = color;
_updatePaint();
}

double get thickness => _thickness;
set thickness(double t) {
_thickness = t;
_updatePaint();
}

void _updatePaint() {
Paint paint = new Paint();
paint.color = drawColor;
paint.style = PaintingStyle.stroke;
paint.strokeWidth = thickness;
_pathHistory.currentPaint = paint;
_pathHistory.setBackgroundColor(backgroundColor);
notifyListeners();
}

void undo() {
if (!isFinished()) {
_pathHistory.undo();
notifyListeners();
}
}

void _notifyListeners() {
notifyListeners();
}

void clear() {
if (!isFinished()) {
_pathHistory.clear();
notifyListeners();
}
}

PictureDetails finish() {
if (!isFinished()) {
_cached = _render(_widgetFinish());
}
return _cached;
}

PictureDetails _render(Size size) {
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder);
_pathHistory.draw(canvas, size);
return new PictureDetails(
recorder.endRecording(), size.width.floor(), size.height.floor());
}

bool isFinished() {
return _cached != null;
}
}




══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (17993): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter (17993): The method 'addAll' was called on null.
I/flutter (17993): Receiver: null
I/flutter (17993): Tried calling: addAll(Instance(length:2) of '_GrowableList')
I/flutter (17993):
I/flutter (17993): When the exception was thrown, this was the stack:
I/flutter (17993): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (17993): #1 _PathHistory.add (package:painter/painter.dart:133:19)
I/flutter (17993): #2 _PainterState._onPanStart (package:painter/painter.dart:62:43)
I/flutter (17993): #3 DragGestureRecognizer.acceptGesture.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:169:47)
I/flutter (17993): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
I/flutter (17993): #5 DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:169:9)
I/flutter (17993): #6 GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:250:25)
I/flutter (17993): #7 GestureArenaManager._tryToResolveArena.<anonymous closure> (package:flutter/src/gestures/arena.dart:231:31)
I/flutter (17993): (elided 2 frames from package dart:async)
I/flutter (17993):
I/flutter (17993): Handler: onStart
I/flutter (17993): Recognizer:
I/flutter (17993): PanGestureRecognizer#80c77(debugOwner: GestureDetector)
I/flutter (17993): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.


Stack Trace:



[ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (11464): oh no!
E/flutter (11464): package:painter/painter.dart 39:5 _PainterState.runAsync
E/flutter (11464): package:painter/painter.dart 35:62 _PainterState.scheduleAsync.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:26 StackZoneSpecification._registerUnaryCallback.<fn>.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:14 StackZoneSpecification._registerUnaryCallback.<fn>
E/flutter (11464): dart:async/zone.dart 1132:38 _rootRunUnary
E/flutter (11464): dart:async/zone.dart 1029:19 _CustomZone.runUnary
E/flutter (11464): dart:async/future_impl.dart 129:18 _FutureListener.handleValue
E/flutter (11464): dart:async/future_impl.dart 642:45 Future._propagateToListeners.handleValueCallback
E/flutter (11464): dart:async/future_impl.dart 671:32 Future._propagateToListeners
E/flutter (11464): dart:async/future_impl.dart 476:7 Future._complete
E/flutter (11464): dart:async/future.dart 316:16 new Future.delayed.<fn> E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback.<fn>









share|improve this question
















I am trying to paint using Float32Int and drawRawPoints but, it's showing that
bad state element.
I have created one list type of Float32Int and in Float32Int var, and then I am storing offset on by on in the list. in paint method using for loop, I am trying to paint. but it shwoing bad state of element in the console



library painter;

import 'package:flutter/widgets.dart' hide Image;
import 'dart:ui';
import 'dart:async';
import 'dart:typed_data';

class Painter extends StatefulWidget {
final PainterController painterController;

Painter(PainterController painterController)
: this.painterController = painterController,
super(key: new ValueKey<PainterController>(painterController));

@override
_PainterState createState() => new _PainterState();
}

class _PainterState extends State<Painter> {
bool _finished;

@override
void initState() {
super.initState();
_finished = false;
widget.painterController._widgetFinish = _finish;
}

Size _finish() {
setState(() {
_finished = true;
});
return context.size;
}

@override
Widget build(BuildContext context) {
Widget child = new CustomPaint(
willChange: true,
painter: new _PainterPainter(widget.painterController._pathHistory,
repaint: widget.painterController),
);
child = new ClipRect(child: child);
if (!_finished) {
child = new GestureDetector(
child: child,
onPanStart: _onPanStart,
onPanUpdate: _onPanUpdate,
onPanEnd: _onPanEnd,
);
}
return new Container(
child: child,
width: double.infinity,
height: double.infinity,
);
}

void _onPanStart(DragStartDetails start) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(start.globalPosition);
widget.painterController._pathHistory.add(pos);
widget.painterController._notifyListeners();
}

void _onPanUpdate(DragUpdateDetails update) {
Offset pos = (context.findRenderObject() as RenderBox)
.globalToLocal(update.globalPosition);
widget.painterController._pathHistory.updateCurrent(pos);
widget.painterController._notifyListeners();
}

void _onPanEnd(DragEndDetails end) {
widget.painterController._pathHistory.endCurrent();
widget.painterController._notifyListeners();
}
}

class _PainterPainter extends CustomPainter {
final _PathHistory _path;

_PainterPainter(this._path, {Listenable repaint}) : super(repaint: repaint);

@override
void paint(Canvas canvas, Size size) {
_path.draw(canvas, size);
}

@override
bool shouldRepaint(_PainterPainter oldDelegate) {
return true;
}
}

class _PathHistory {
List<MapEntry<Path, Paint>> _paths;
Paint currentPaint;
Paint _backgroundPaint;
bool _inDrag;

_PathHistory() {
_paths = new List<MapEntry<Path, Paint>>();
_inDrag = false;
_backgroundPaint = new Paint();
}

void setBackgroundColor(Color backgroundColor) {
_backgroundPaint.color = backgroundColor;
}

void undo() {
if (!_inDrag) {
_paths.removeLast();
}
}

void clear() {
if (!_inDrag) {
_paths.clear();
}
}

static List<Float32List> list = ;

Float32List float32list;
// Float32List floatPoints = Float32List.fromList(list);
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));
float32list.addAll([startPoint.dx, startPoint.dy]);
}
}

void updateCurrent(Offset nextPoint) {
if (_inDrag) {
// path.lineTo(nextPoint.dx, nextPoint.dy);
float32list.addAll([nextPoint.dx, nextPoint.dy]);
}
}

void endCurrent() {
_inDrag = false;
list.add(float32list);
}

void draw(Canvas canvas, Size size) {
Paint p = new Paint();
p.strokeCap = StrokeCap.round;
p.strokeWidth = 20.0;
canvas.drawRect(
new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _backgroundPaint);

for (int i = 0; i < list.length; i++) {
if (list.isNotEmpty) canvas.drawRawPoints(PointMode.lines, list[i], p);
}
}
}

typedef PictureDetails PictureCallback();

class PictureDetails {
final Picture picture;
final int width;
final int height;

const PictureDetails(this.picture, this.width, this.height);

Image toImage() {
return picture.toImage(width, height);
}

Future<Uint8List> toPNG() async {
return (await toImage().toByteData(format: ImageByteFormat.png))
.buffer
.asUint8List();
}
}

class PainterController extends ChangeNotifier {
Color _drawColor = new Color.fromARGB(255, 0, 0, 0);
Color _backgroundColor = new Color.fromARGB(255, 255, 255, 255);

double _thickness = 1.0;
PictureDetails _cached;
_PathHistory _pathHistory;
ValueGetter<Size> _widgetFinish;

PainterController() {
_pathHistory = new _PathHistory();
}

Color get drawColor => _drawColor;
set drawColor(Color color) {
_drawColor = color;
_updatePaint();
}

Color get backgroundColor => _backgroundColor;
set backgroundColor(Color color) {
_backgroundColor = color;
_updatePaint();
}

double get thickness => _thickness;
set thickness(double t) {
_thickness = t;
_updatePaint();
}

void _updatePaint() {
Paint paint = new Paint();
paint.color = drawColor;
paint.style = PaintingStyle.stroke;
paint.strokeWidth = thickness;
_pathHistory.currentPaint = paint;
_pathHistory.setBackgroundColor(backgroundColor);
notifyListeners();
}

void undo() {
if (!isFinished()) {
_pathHistory.undo();
notifyListeners();
}
}

void _notifyListeners() {
notifyListeners();
}

void clear() {
if (!isFinished()) {
_pathHistory.clear();
notifyListeners();
}
}

PictureDetails finish() {
if (!isFinished()) {
_cached = _render(_widgetFinish());
}
return _cached;
}

PictureDetails _render(Size size) {
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder);
_pathHistory.draw(canvas, size);
return new PictureDetails(
recorder.endRecording(), size.width.floor(), size.height.floor());
}

bool isFinished() {
return _cached != null;
}
}




══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (17993): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter (17993): The method 'addAll' was called on null.
I/flutter (17993): Receiver: null
I/flutter (17993): Tried calling: addAll(Instance(length:2) of '_GrowableList')
I/flutter (17993):
I/flutter (17993): When the exception was thrown, this was the stack:
I/flutter (17993): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (17993): #1 _PathHistory.add (package:painter/painter.dart:133:19)
I/flutter (17993): #2 _PainterState._onPanStart (package:painter/painter.dart:62:43)
I/flutter (17993): #3 DragGestureRecognizer.acceptGesture.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:169:47)
I/flutter (17993): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
I/flutter (17993): #5 DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:169:9)
I/flutter (17993): #6 GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:250:25)
I/flutter (17993): #7 GestureArenaManager._tryToResolveArena.<anonymous closure> (package:flutter/src/gestures/arena.dart:231:31)
I/flutter (17993): (elided 2 frames from package dart:async)
I/flutter (17993):
I/flutter (17993): Handler: onStart
I/flutter (17993): Recognizer:
I/flutter (17993): PanGestureRecognizer#80c77(debugOwner: GestureDetector)
I/flutter (17993): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.
I/flutter (17993): Another exception was thrown: NoSuchMethodError: The method 'addAll' was called on null.


Stack Trace:



[ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (11464): oh no!
E/flutter (11464): package:painter/painter.dart 39:5 _PainterState.runAsync
E/flutter (11464): package:painter/painter.dart 35:62 _PainterState.scheduleAsync.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:26 StackZoneSpecification._registerUnaryCallback.<fn>.<fn>
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 129:14 StackZoneSpecification._registerUnaryCallback.<fn>
E/flutter (11464): dart:async/zone.dart 1132:38 _rootRunUnary
E/flutter (11464): dart:async/zone.dart 1029:19 _CustomZone.runUnary
E/flutter (11464): dart:async/future_impl.dart 129:18 _FutureListener.handleValue
E/flutter (11464): dart:async/future_impl.dart 642:45 Future._propagateToListeners.handleValueCallback
E/flutter (11464): dart:async/future_impl.dart 671:32 Future._propagateToListeners
E/flutter (11464): dart:async/future_impl.dart 476:7 Future._complete
E/flutter (11464): dart:async/future.dart 316:16 new Future.delayed.<fn> E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 209:15 StackZoneSpecification._run
E/flutter (11464): package:stack_trace/src/stack_zone_specification.dart 119:48 StackZoneSpecification._registerCallback.<fn>






android dart flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 6:21









Günter Zöchbauer

322k68958893




322k68958893










asked Nov 23 '18 at 11:25









satishsatish

150113




150113













  • post 4-6 top frames from the stacktrace

    – pskink
    Nov 24 '18 at 7:07











  • Whatever I am getting the error in console, I added at end of my code.

    – satish
    Nov 26 '18 at 6:05











  • in the end, the stack is also given.

    – satish
    Nov 26 '18 at 6:13



















  • post 4-6 top frames from the stacktrace

    – pskink
    Nov 24 '18 at 7:07











  • Whatever I am getting the error in console, I added at end of my code.

    – satish
    Nov 26 '18 at 6:05











  • in the end, the stack is also given.

    – satish
    Nov 26 '18 at 6:13

















post 4-6 top frames from the stacktrace

– pskink
Nov 24 '18 at 7:07





post 4-6 top frames from the stacktrace

– pskink
Nov 24 '18 at 7:07













Whatever I am getting the error in console, I added at end of my code.

– satish
Nov 26 '18 at 6:05





Whatever I am getting the error in console, I added at end of my code.

– satish
Nov 26 '18 at 6:05













in the end, the stack is also given.

– satish
Nov 26 '18 at 6:13





in the end, the stack is also given.

– satish
Nov 26 '18 at 6:13












1 Answer
1






active

oldest

votes


















0














Your exception comes from



float32list.addAll([startPoint.dx, startPoint.dy]);


being called when float32list is null as the exception output points out.



Float32List float32list;


should be



Float32List float32list = Float32List.fromList(list);


or float32list be initialized by other means.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445821%2fflutter-paint-using-float32int-and-drawrawpoints%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your exception comes from



    float32list.addAll([startPoint.dx, startPoint.dy]);


    being called when float32list is null as the exception output points out.



    Float32List float32list;


    should be



    Float32List float32list = Float32List.fromList(list);


    or float32list be initialized by other means.






    share|improve this answer




























      0














      Your exception comes from



      float32list.addAll([startPoint.dx, startPoint.dy]);


      being called when float32list is null as the exception output points out.



      Float32List float32list;


      should be



      Float32List float32list = Float32List.fromList(list);


      or float32list be initialized by other means.






      share|improve this answer


























        0












        0








        0







        Your exception comes from



        float32list.addAll([startPoint.dx, startPoint.dy]);


        being called when float32list is null as the exception output points out.



        Float32List float32list;


        should be



        Float32List float32list = Float32List.fromList(list);


        or float32list be initialized by other means.






        share|improve this answer













        Your exception comes from



        float32list.addAll([startPoint.dx, startPoint.dy]);


        being called when float32list is null as the exception output points out.



        Float32List float32list;


        should be



        Float32List float32list = Float32List.fromList(list);


        or float32list be initialized by other means.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 6:26









        Günter ZöchbauerGünter Zöchbauer

        322k68958893




        322k68958893






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445821%2fflutter-paint-using-float32int-and-drawrawpoints%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'