英文:
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("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
答案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: "I agree GDPR available HERE",
child: RichText(...
Tip: You can use SemanticsDebugger
to visualize the semantics.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论