From 1633c47dda49e5470989d0518e65fe113adbfcda Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Thu, 15 Aug 2024 14:30:03 -0700 Subject: [PATCH] Improve asserts on Element.mount (#153477) ## Description In debugging an issue with mount, I hit one of these asserts, and I thought it would be a much better assert with some context. ## Tests - No test changes because the change is only to the output string of an assert. --- .../flutter/lib/src/widgets/framework.dart | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 2feb53a2e7..cfbe6523c4 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -4217,10 +4217,22 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// method, as in `super.mount(parent, newSlot)`. @mustCallSuper void mount(Element? parent, Object? newSlot) { - assert(_lifecycleState == _ElementLifecycle.initial); - assert(_parent == null); - assert(parent == null || parent._lifecycleState == _ElementLifecycle.active); - assert(slot == null); + assert( + _lifecycleState == _ElementLifecycle.initial, + 'This element is no longer in its initial state (${_lifecycleState.name})', + ); + assert( + _parent == null, + "This element already has a parent ($_parent) and it shouldn't have one yet.", + ); + assert( + parent == null || parent._lifecycleState == _ElementLifecycle.active, + 'Parent ($parent) should be null or in the active state (${parent._lifecycleState.name})', + ); + assert( + slot == null, + "This element already has a slot ($slot) and it shouldn't", + ); _parent = parent; _slot = newSlot; _lifecycleState = _ElementLifecycle.active;