I am trying to look for '@' in a piece of text and then asynchronously gather a displayName for that tag. The problem I am running into is that my FutureBuilder keeps returning null.
The error I get is this.
════════ Exception caught by widgets library ════════
The following assertion was thrown building FutureBuilder(dirty, state: _FutureBuilderState#151f7): A build function returned null.
The offending widget is: FutureBuilder Build functions must never return null.
My code is this:
Container(
width: double.infinity,
child: FutureBuilder(
initialData: SelectableText(''),
future: buildSelectableText(context),
builder: (BuildContext context, AsyncSnapshot<SelectableText> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return Center(child: CircularProgressIndicator());
return snapshot.data;
}
),
),
Future<SelectableText> buildSelectableText(BuildContext context) async {
return SelectableText.rich(
TextSpan(
text:'',
children: data["comment"].split(' ').map<InlineSpan>((word) async {
return word.startsWith('@') && word.length > 1 ?
TextSpan(
text: ' '+ (await context.read<UserDataModel>().fetchUser(word)).displayName,
style: TextStyle(color: Colors.blue),
): TextSpan(text: ' ' + word);
}).toList()
),
textAlign: TextAlign.justify,
);
}
There should probably be a simple fix but I can't find it