localized_rich_text 0.0.7 copy "localized_rich_text: ^0.0.7" to clipboard
localized_rich_text: ^0.0.7 copied to clipboard

A flutter plugin to facilitate the localization of a RichText

example/lib/main.dart

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:localized_rich_text/localized_rich_text.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final textToLocalize = "Hi #name, how are you? I'm #myName!";
  final name = "Jhon";
  final myName = "Simon";

  final textSpanProperties = TextSpanProperties(
    recognizer: TapGestureRecognizer()
      ..onTap = () {
        //Do something
      },
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Localized RichText'),
      ),
      body: Center(
        child: LocalizedRichText(
          text: textToLocalize,
          defaultTextStyle: Theme.of(context).textTheme.bodyLarge!,
          keys: [
            LocalizedRichTextKey(
              key: '#name',
              value: name,
              textStyle: Theme.of(context).textTheme.titleMedium!.copyWith(
                    fontStyle: FontStyle.italic,
                  ),
              textSpanProperties: textSpanProperties,
            ),
            LocalizedRichTextKey(
              key: '#myName',
              value: myName,
              textStyle: Theme.of(context).textTheme.titleMedium!.copyWith(
                    fontStyle: FontStyle.italic,
                  ),
            ),
          ],
        ),
      ),
    );
  }
}
4
likes
140
pub points
76%
popularity

Publisher

unverified uploader

A flutter plugin to facilitate the localization of a RichText

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on localized_rich_text