Ive been trying to add WidgetSpans to a TextField (via the buildTextSpan() in a TextEditingController) and ran into the crash: "Failed assertion: [..] : 'dimensions != null': is not true". While trying to find a solution ive only ran across people with similar issues, but wasnt able to find a solution to this. My Code(and Problem) is similar to the comment posted on the issue https://github.com/flutter/flutter/issues/30688#issuecomment-870034058.
@override
TextSpan buildTextSpan({required BuildContext context, TextStyle? style, required bool withComposing}) {
final atIndex = text.indexOf('@');
var spans = <InlineSpan>[];
if (atIndex != -1) {
spans.add(TextSpan(text: text.substring(0, atIndex)));
spans.add(
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Card(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text('@'),
),
),
),
);
spans.add(TextSpan(text: text.substring(1 + atIndex)));
} else {
spans.add(TextSpan(text: text));
}
return TextSpan(
children: spans,
);
}
Is there any fix/workaround for this failed assertion?