localized_string 0.0.2 copy "localized_string: ^0.0.2" to clipboard
localized_string: ^0.0.2 copied to clipboard

outdated

LocalizedString is an implementation of String that depends on BuildContext.

localized_string #

LocalizedString is an implementation of String that depends on BuildContext.

It can be helpful if you need to return a string which should be localized in the future but you don't have a context. Simple example is validator, it should return localized string but it can't use the context because validator is encapsulated from it.

Examples #

To create localized string use this snippet:

LocalizedString((context) => AppLoc.of(context).title);

To compare localized string you should specify key for each of them:

s1 = LocalizedString((context) => AppLoc.of(context).title, "title");
s2 = LocalizedString((context) => AppLoc.of(context).title, "title");
s3 = LocalizedString((context) => AppLoc.of(context).desc, "desc");

assert(s1 == s2);
assert(s1 != s3);

Also you can create LocalizedString from regular string:

LocalizedString.fromString("Hello world"); 

it will create LocalizedString with the same key as its value.

To localize string, just call localize method:

s1 = LocalizedString((context) => AppLoc.of(context).title, "title");
s1.localize(context);
2
likes
0
pub points
40%
popularity

Publisher

verified publisherandrey.kabylin.ru

LocalizedString is an implementation of String that depends on BuildContext.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on localized_string