Skip to content

Instantly share code, notes, and snippets.

@5lineofcode
Created December 26, 2019 10:13
Show Gist options
  • Save 5lineofcode/48d1f65c0b13eb9f7420b2ca65e95df1 to your computer and use it in GitHub Desktop.
Save 5lineofcode/48d1f65c0b13eb9f7420b2ca65e95df1 to your computer and use it in GitHub Desktop.
GetColorizedString
List<Widget> getColorizedString(String str) {
Map<String, dynamic> stringCode = {
"red.": Colors.red,
"blue.": Colors.blue,
"yellow.": Colors.yellow,
"green.": Colors.green,
"r.": Colors.red,
"b.": Colors.blue,
"y.": Colors.yellow,
"g.": Colors.green,
"o.": Colors.orange,
};
List<Widget> widgetList = [];
var words = str.split(" ");
words.forEach((word) {
var color = Colors.grey[900];
stringCode.forEach((key, value) {
if (word.contains(key)) {
color = value;
}
});
widgetList.add(Text(
"$word ",
style: TextStyle(
color: color,
fontSize: 20.0,
),
));
});
return widgetList;
}
/*
Implementation
Use Wrap:
*/
Wrap(
children: getColorizedString(
"Hello blue.Telegram , red.apa red.kabar?\n g.Gimana y.nih?\n o.Tahun o.baruan o.gak?",
),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment