From aea3159ddc5a54c904c44c68d823469ca24da40d Mon Sep 17 00:00:00 2001 From: appflowy <86001920+appflowy@users.noreply.github.com> Date: Sat, 23 Oct 2021 23:05:45 +0800 Subject: [PATCH] [fix]: cursorConnt.color notify the text_line to repaint if it was disposed (#428) --- lib/src/widgets/text_line.dart | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 {