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

huangapple go评论58阅读模式
英文:

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

问题

我在Flutter中有这段代码:

Widget build(BuildContext context) {
  return ListView(
    children: [
      Container(
        margin: EdgeInsets.only(left: 15, right: 15, top: 30),
        child: Text("输入您的电话", 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: "电话",
            labelStyle: TextStyle(color: Colors.black),
            icon: Icon(Icons.phone_outlined),
          ),
        ),
      ),
      Container(
        margin: EdgeInsets.only(left: 15, right: 15, top: 20),
        child: Text("您将收到短信中的验证码", style: TextStyle(fontSize: 16)),
      ),
      Container(
        margin: EdgeInsets.only(right: 15, top: 20),
        child: CheckboxListTile(
          title: RichText(
            text: TextSpan(
              children: [
                TextSpan(
                  text: '我同意GDPR',
                  style: TextStyle(color: Colors.black),
                ),
                TextSpan(
                  text: ' 在这里可用',
                  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: ' 在这里阅读更多',
                recognizer: TapGestureRecognizer()
                  ..onTap = () async {
                    await launchUrl(Uri.parse('https://xy.com/gdpr.pdf'), mode: LaunchMode.externalApplication);
                  },
                style: TextStyle(color: mainAppColor, fontSize: 16),
              ),
            ],
          ),
        ),
      ),
    ],
  );
}

这个部分是你提供的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(&quot;Enter your phone&quot;,
              style: TextStyle(fontSize: 16)),
        ),
        Container(
          margin: EdgeInsets.only(left: 15, right: 15),
          child: TextField(
            controller: phoneNumber,
            keyboardType: TextInputType.number,
            autofillHints: [AutofillHints.telephoneNumberNational],
            inputFormatters: &lt;TextInputFormatter&gt;[
              FilteringTextInputFormatter.digitsOnly,
            ],
            decoration: InputDecoration(
              border: UnderlineInputBorder(),
              labelText: &quot;Phone&quot;,
              labelStyle: TextStyle(color: Colors.black),
              icon: Icon(Icons.phone_outlined),
            ),
          ),
        ),

        Container(
          margin: EdgeInsets.only(left: 15, right: 15, top: 20),
          child: Text(&quot;You will receive code in SMS&quot;,
              style: TextStyle(fontSize: 16)),
        ),
        Container(
            margin: EdgeInsets.only(right: 15, top: 20),
            child:
            CheckboxListTile(
              title: RichText(
                text: TextSpan(
                  children: [
                    TextSpan(
                      text: &#39;I agree GDPR&#39;,
                      style: TextStyle(color: Colors.black),
                    ),
                    TextSpan(
                      text: &#39; available HERE&#39;,
                      style: TextStyle(color: mainAppColor),
                      recognizer: TapGestureRecognizer()..onTap = () async{
                        await launchUrl(Uri.parse(&#39;https://xy.com/gdpr.pdf&#39;), 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: &#39;gdpr&#39;,
                  style: TextStyle(color: Colors.black, fontSize: 16),
                ),
                TextSpan(
                  text: &#39; read more here&#39;,
                  recognizer: TapGestureRecognizer()..onTap = () async{
                    await launchUrl(Uri.parse(&#39;https://xy.com/gdpr.pdf&#39;), 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:
&#39;package:flutter/src/semantics/semantics.dart&#39;: Failed assertion: line 3105 pos 16: &#39;node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent&#39;: 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.&lt;anonymous closure&gt; (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 Flutter Failed assertion: line 3105 pos 16: 'node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent': is not true

答案1

得分: 5

这是一个自2020年以来的未解决问题:https://github.com/flutter/flutter/issues/54665

在该讨论中,有一些解决方法,比如将RichText包装在ExcludeSemantics中,这也适用于您的情况。

希望这对您有所帮助。

英文:

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.

答案2

得分: 0

我建议不要为了辅助功能将其包裹在ExcludeSemantics中,而是将其包裹在Semantics中,然后排除其后代:

Semantics(
  excludeSemantics: true,
  label: "我同意 GDPR 在此可用",
  child: RichText(...

提示: 您可以使用SemanticsDebugger来可视化语义信息。

英文:

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: &quot;I agree GDPR available HERE&quot;,
  child: RichText(...

Tip: You can use SemanticsDebugger to visualize the semantics.

huangapple
  • 本文由 发表于 2023年2月24日 00:58:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547986.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定