Task: Add TextFormatter function to format the string with args
This commit is contained in:
33
lib/text_formatter.dart
Normal file
33
lib/text_formatter.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
class TextFormatter {
|
||||
String? text;
|
||||
|
||||
TextFormatter(String? text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
String? format(List<dynamic> args) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var msg = text;
|
||||
args.asMap().forEach((index, element) {
|
||||
msg = msg?.replaceAll('{$index}', element);
|
||||
});
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
String? decorate(Map<String, dynamic> args) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var msg = text;
|
||||
args.forEach((index, element) {
|
||||
msg = msg?.replaceAll('{$index}', element);
|
||||
});
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user