I am trying to display some text in different colors. I learned about the RichText
widget and used it as follows;
Future<List<TextSpan>> listOfEventsAtDay({String day, String monthNum}) async {
final result = await DatabaseHelper.instance
.queryForEventsAtDay(mnth: monthNum, dy: day);
List<TextSpan> textSpans = [];
int count = result.length;
for (int i = 0; i < count; i++) {
final String string = "-${result[i]['year']}: ${result[i]['title']}\n";
textSpans.add(TextSpan(
text: string,
));
}
return textSpans;
}
which is later called on;
ListTile( title: RichText(text: TextSpan(children: snapshot.data),
I don't want any complex stylings for now. In dark mode, the text should be in white, and in the light mode, it should be in black. That's all. But problem is, the text is always white. Why doesn't it adjust with brightness settings? Is there any way to accomplish this? Please help me...
Found a solution.
style: DefaultTextStyle.of(context).style
Full snippet;
Future<List<TextSpan>> listOfEventsAtDay({String day, String monthNum, BuildContext context}) async {
final result = await DatabaseHelper.instance
.queryForEventsAtDay(mnth: monthNum, dy: day);
List<TextSpan> textSpans = [];
int count = result.length;
for (int i = 0; i < count; i++) {
final String string = "-${result[i]['year']}: ${result[i]['title']}\n";
textSpans.add(TextSpan(
text: string,
style: DefaultTextStyle.of(context).style,
));
}
This fixed it.