FLUTTER ECOSYSTEM

LaTrita97/localized_rich_text

Um plugin do Flutter para facilitar a localização de um RichText

Capa do projeto localized_rich_text
Stars
1
Forks
4
Último push (UTC)
23 de nov. de 2023
Status do projeto
Ativo
Simone Bruziches GitHub avatar
GITHUB User

Simone Bruziches ↗

Flutter developer, founder of Moneymi and hooz

Simone Bruziches
LinguagensDartRubyHTMLKotlinSwiftObjective-CCMakeShellCC++

Pacotes publicados por este repositório

Dependências usadas

Lista de dependências 4 itens
  • flutter{"sdk":"flutter"}
  • flutter_web_plugins{"sdk":"flutter"}
  • flutter_testDesenvolvimento{"sdk":"flutter"}
  • flutter_lintsDesenvolvimento^1.0.0

README original

Texto original em inglês. Visite o GitHub para a versão atual.

Expandir / recolher README

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.7

Usage

final textToLocalize = "Hi #name, how are you?";
final userName = "Jhon";

final textSpanProperties = TextSpanProperties(
    recognizer: TapGestureRecognizer()
      ..onTap = () {
        //Do something
      },
  );
...
LocalizedRichText(
  text: textToLocalize,
  defaultTextStyle: Theme.of(context).textTheme.bodyText1!,
  keys: [
    LocalizedRichTextKey(
      key: '#name',
      value: userName,
      textStyle: Theme.of(context).textTheme.subtitle1!,
      textSpanProperties: textSpanProperties,
    ),
  ],
)

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.

The keys will be ordered by the order in which they are been inserted in the String to localize.
This means that the order in which you pass the keys inside the keys array isn't important.

LocalizedRichText(
  ...,
  keys: [
    LocalizedRichTextKey(
      key: '#name',
      value: userName,
      textStyle: Theme.of(context).textTheme.subtitle1!,
    ),
  ],
)