diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index f87645ab..736a9c01 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -413,7 +413,7 @@ class RenderEditableTextLine extends RenderEditableBox { color = c; if (containsTextSelection()) { - markNeedsPaint(); + safeMarkNeedsPaint(); } } @@ -425,7 +425,7 @@ class RenderEditableTextLine extends RenderEditableBox { final containsSelection = containsTextSelection(); if (attached && containsCursor()) { cursorCont.removeListener(markNeedsLayout); - cursorCont.color.removeListener(markNeedsPaint); + cursorCont.color.removeListener(safeMarkNeedsPaint); } textSelection = t; @@ -433,11 +433,11 @@ class RenderEditableTextLine extends RenderEditableBox { _containsCursor = null; if (attached && containsCursor()) { cursorCont.addListener(markNeedsLayout); - cursorCont.color.addListener(markNeedsPaint); + cursorCont.color.addListener(safeMarkNeedsPaint); } if (containsSelection || containsTextSelection()) { - markNeedsPaint(); + safeMarkNeedsPaint(); } } @@ -642,7 +642,7 @@ class RenderEditableTextLine extends RenderEditableBox { } if (containsCursor()) { cursorCont.addListener(markNeedsLayout); - cursorCont.color.addListener(markNeedsPaint); + cursorCont.color.addListener(safeMarkNeedsPaint); } } @@ -654,7 +654,7 @@ class RenderEditableTextLine extends RenderEditableBox { } if (containsCursor()) { cursorCont.removeListener(markNeedsLayout); - cursorCont.color.removeListener(markNeedsPaint); + cursorCont.color.removeListener(safeMarkNeedsPaint); } } @@ -883,6 +883,14 @@ class RenderEditableTextLine extends RenderEditableBox { affinity: position.affinity, ); } + + void safeMarkNeedsPaint() { + if (!attached) { + //Should not paint if it was unattach. + return; + } + safeMarkNeedsPaint(); + } } class _TextLineElement extends RenderObjectElement {