From 39df2111f7b508aaa965c11edc77da87a00bbc8b Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Fri, 28 May 2021 15:24:05 +0700 Subject: [PATCH] Fixed Text Formatter on dynamic to string --- CHANGELOG.md | 5 ++++- lib/text_formatter.dart | 26 ++++++++++++++++++++++---- pubspec.yaml | 4 ++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e1252..725c897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,4 +30,7 @@ - Add TextFormatter for format the string with args ## 1.0.7 -- Removed example "example_flutter_secure_storage_provider.dart" \ No newline at end of file +- Removed example "example_flutter_secure_storage_provider.dart" + +## 1.0.8 +- Fixed Text Formatter on dynamic to string \ No newline at end of file diff --git a/lib/text_formatter.dart b/lib/text_formatter.dart index 08bccf3..405afc2 100644 --- a/lib/text_formatter.dart +++ b/lib/text_formatter.dart @@ -10,22 +10,40 @@ class TextFormatter { return null; } + if (args.isEmpty) { + return text; + } + var msg = text; args.asMap().forEach((index, element) { - msg = msg?.replaceAll('{$index}', element); + var _replaced = ''; + if (element != null) { + _replaced = element.toString(); + } + + msg = msg?.replaceAll('{$index}', _replaced); }); return msg; } - String? decorate(Map args) { + String? decorate(Map params) { if (text == null) { return null; } + if (params.isEmpty) { + return text; + } + var msg = text; - args.forEach((index, element) { - msg = msg?.replaceAll('{$index}', element); + params.forEach((index, element) { + var _replaced = ''; + if (element != null) { + _replaced = element.toString(); + } + + msg = msg?.replaceAll('{$index}', _replaced); }); return msg; diff --git a/pubspec.yaml b/pubspec.yaml index 11d459d..5d17a8c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: configurable -description: System Configuration and Dotenv Environment for Dart and Flutter -version: 1.0.7 +description: System Configuration, Dotenv Environment and Text Formatter for Dart and Flutter +version: 1.0.8 homepage: https://github.com/CUBETIQ/system-config-dart repository: https://github.com/CUBETIQ/system-config-dart.git