localized_rich_text 0.0.1
localized_rich_text: ^0.0.1 copied to clipboard
A flutter plugin to facilitate the localization of a RichText
A flutter plugin to facilitate the localization of a RichText.
Getting started #
Install the library in your pubspec.yaml.
dependencies:
localized_rich_text: ^0.0.1
Usage #
final textToLocalize = "Hi #name, how are you?";
final userName = "Jhon";
...
LocalizedRichText(
text: textToLocalize,
defaultTextStyle: Theme.of(context).textTheme.bodyText1!,
keys: [
LocalizedRichTextKey(
key: '#name',
value: userName,
textStyle: Theme.of(context).textTheme.subtitle1!,
),
],
)
Parameters explanation #
text
This must be the String to localize.
The dynamic values inside the text have to be unique,
you can mark them with a special character, or you can use a unique value.
The string could be:
final textToLocalize = "Hi #name, how are you?";
or
AppLocalizations.of(context)!.title,
For more info about internationalization you can check the
flutter documentation.
defaultTextStyle
This is the TextStyle used for the static words.
keys
This is the List that has to contain the dynamic values.
Each dynamic value has to be passed like an LocalizedRichTextKey object.
This list cannot be empty.
It could be:
LocalizedRichText(
...,
keys: [
LocalizedRichTextKey(
key: '#name',
value: userName,
textStyle: Theme.of(context).textTheme.subtitle1!,
),
],
)