Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Failed assertion: line 3105 pos 16: 'node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent': is not true

Tags:

flutter

I have code in Flutter:

  Widget build(BuildContext context) {
    return ListView(
      children: [
        Container(
          margin: EdgeInsets.only(left: 15, right: 15, top: 30),
          child: Text("Enter your phone",
              style: TextStyle(fontSize: 16)),
        ),
        Container(
          margin: EdgeInsets.only(left: 15, right: 15),
          child: TextField(
            controller: phoneNumber,
            keyboardType: TextInputType.number,
            autofillHints: [AutofillHints.telephoneNumberNational],
            inputFormatters: <TextInputFormatter>[
              FilteringTextInputFormatter.digitsOnly,
            ],
            decoration: InputDecoration(
              border: UnderlineInputBorder(),
              labelText: "Phone",
              labelStyle: TextStyle(color: Colors.black),
              icon: Icon(Icons.phone_outlined),
            ),
          ),
        ),

        Container(
          margin: EdgeInsets.only(left: 15, right: 15, top: 20),
          child: Text("You will receive code in SMS",
              style: TextStyle(fontSize: 16)),
        ),
        Container(
            margin: EdgeInsets.only(right: 15, top: 20),
            child:
            CheckboxListTile(
              title: RichText(
                text: TextSpan(
                  children: [
                    TextSpan(
                      text: 'I agree GDPR',
                      style: TextStyle(color: Colors.black),
                    ),
                    TextSpan(
                      text: ' available HERE',
                      style: TextStyle(color: mainAppColor),
                      recognizer: TapGestureRecognizer()..onTap = () async{
                        await launchUrl(Uri.parse('https://xy.com/gdpr.pdf'), mode: LaunchMode.externalApplication);
                      },
                    )
                  ],
                ),
              ),
              value: acceptedGDPR,
              onChanged: (newValue) {
                setState(() {
                  acceptedGDPR = newValue!;
                });
              },
              controlAffinity: ListTileControlAffinity.leading,
            )
        ),

        Container(
          margin: EdgeInsets.only(left: 15, right: 15, top: 20),
          child: RichText(
            text: TextSpan(
              children: [
                TextSpan(
                  text: 'gdpr',
                  style: TextStyle(color: Colors.black, fontSize: 16),
                ),
                TextSpan(
                  text: ' read more here',
                  recognizer: TapGestureRecognizer()..onTap = () async{
                    await launchUrl(Uri.parse('https://xy.com/gdpr.pdf'), mode: LaunchMode.externalApplication);
                  },
                  style: TextStyle(color: mainAppColor, fontSize: 16),
                )
              ],
            ),
          ),
        ),
      ],
    );
  }

Everything works perfectly fine. But every time when I open this Stateful Widget I get this error message:

The following assertion was thrown during a scheduler callback:
'package:flutter/src/semantics/semantics.dart': Failed assertion: line 3105 pos 16: 'node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack: 
#2      SemanticsOwner.sendSemanticsUpdate (package:flutter/src/semantics/semantics.dart:3105:16)
#3      PipelineOwner.flushSemantics (package:flutter/src/rendering/object.dart:1246:24)
#4      RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:521:21)
#5      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:865:13)
#6      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:381:5)
#7      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15)
#8      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1218:9)
#9      SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:942:7)
#13     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)

After some investigation I found the source of this error (in CheckboxListTile, NOT in last Container):

recognizer: TapGestureRecognizer()..onTap = () async{
   //await launchUrl... this line is not causing the error
},

When I remove this recognizer from TextSpan error does not show again. But I need it there. So when everything works fine, why am getting this error and how to fix it? Thank you for all advices :)

like image 401
AdamA Avatar asked Oct 30 '25 05:10

AdamA


2 Answers

It's an open issue since 2020: https://github.com/flutter/flutter/issues/54665

In the thread there are a few workarounds, such as wrapping the RichText in ExcludeSemantics, which should apply to your case too.

Hope this helps.

like image 132
Mauro Vanetti Avatar answered Oct 31 '25 19:10

Mauro Vanetti


I would suggest not wrapping it in ExcludeSemantics for the sake of Accessibility, instead wrap it Semantics and then exclude its descendants:

Semantics(
  excludeSemantics: true,
  label: "I agree GDPR available HERE",
  child: RichText(...

Tip: You can use SemanticsDebugger to visualize the semantics.

like image 33
Saad Ahmed Avatar answered Oct 31 '25 20:10

Saad Ahmed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!