TextReplacer class
Properties
-
hashCode
→ int
-
The hash code for this object.
no setterinherited
-
runtimeType
→ Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(Invocation invocation)
→ dynamic
-
Invoked when a nonexistent method or property is accessed.
inherited
-
toString()
→ String
-
A string representation of this object.
inherited
Static Methods
-
replace(String input, Map<String, Object?> args)
→ String
-
final inp = '{IS_LOADING ? "Loading..." : "{COUNT > 1 ? "COUNT items" : "{COUNT == 1 ? "One item" : "No items"}"}"}';
TextReplacer.replace(inp, {'COUNT': 1, 'IS_LOADING': true}); // Loading...
TextReplacer.replace(inp, {'COUNT': 0, 'IS_LOADING': false}); // No items
TextReplacer.replace(inp, {'COUNT': 1, 'IS_LOADING': false}); // One item
TextReplacer.replace(inp, {'COUNT': 2, 'IS_LOADING': false}); // 2 items
final inp1 = "There {NUMBER > 1 ? \"are NUMBER items\" : \"is an item\"} in stock";
TextReplacer.replace(inp1, {'NUMBER': 1}); // There is an item in stock
TextReplacer.replace(inp1, {'NUMBER': 2}); // There are 2 items in stock
final inp2 = "Status: {STATUS == active ? \"activated!\" : \"canceled!\"}";
TextReplacer.replace(inp2, {'STATUS': "active"}); // Status: activated!
TextReplacer.replace(inp2, {'STATUS': "inactive"}); // Status: canceled!
final inp3 = "Status: {IS_ACTIVATED ? \"activated!\" : \"inactivated!\"}";
TextReplacer.replace(inp3, {'IS_ACTIVATED': true}); // Status: activated!
TextReplacer.replace(inp3, {'IS_ACTIVATED': false}); // Status: inactivated!
final inp4 = "Last seen: {TIME: {a:now, b:3 min ago}}";
TextReplacer.replace(inp4, {"TIME": "a"}); // Last seen: now
TextReplacer.replace(inp4, {"TIME": "b"}); // Last seen: 3 min ago