flutter_open_chinese_convert 0.9.0 copy "flutter_open_chinese_convert: ^0.9.0" to clipboard
flutter_open_chinese_convert: ^0.9.0 copied to clipboard

flutter_open_chinese_convert bridges OpenCC (Open Chinese Convert) to your Flutter projects.

example/lib/main.dart

// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var _index = 0;
  final _original = '鼠标里面的硅二极管坏了,导致光标分辨率降低。\n滑鼠裡面的矽二極體壞了,導致游標解析度降低。';
  var _converted = '';

  @override
  void initState() {
    super.initState();
    _convert();
  }

  Future<void> _convert() async {
    var text = _original;
    var option = ChineseConverter.allOptions[_index];
    var result = await ChineseConverter.convert(
      text,
      option,
      inBackground: true,
    );
    setState(() => _converted = result);
  }

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Row(children: <Widget>[Text('Open Chinese Convert')]),
          ),
          body: SafeArea(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                buildMenu(context),
                const Divider(),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(
                    'Original:',
                    style: Theme.of(context).textTheme.headlineLarge,
                  ),
                ),
                Padding(
                    padding: const EdgeInsets.all(8.0), child: Text(_original)),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(
                    'Conveted:',
                    style: Theme.of(context).textTheme.headlineLarge,
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(_converted ?? ''),
                ),
              ],
            ),
          ),
        ),
      );

  Widget buildMenu(BuildContext context) => PopupMenuButton<int>(
        elevation: 2,
        child: SizedBox(
          width: double.infinity,
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text(
              ChineseConverter.allOptions[_index].chineseDescription,
              style: TextStyle(color: Theme.of(context).primaryColor),
            ),
          ),
        ),
        onSelected: (i) {
          _index = i;
          _convert();
        },
        itemBuilder: (context) => List.of(
          ChineseConverter.allOptions
              .asMap()
              .map(
                (i, x) => MapEntry(
                  i,
                  PopupMenuItem(
                    value: i,
                    child: Row(
                      children: <Widget>[
                        SizedBox(
                          width: 40,
                          child: i == _index
                              ? const Icon(Icons.check)
                              : Container(),
                        ),
                        Expanded(
                          child: Text(
                            x.chineseDescription,
                            style: const TextStyle(fontSize: 12.0),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              )
              .values,
        ),
      );
}
17
likes
150
points
517
downloads

Documentation

API reference

Publisher

verified publisherzonble.net

Weekly Downloads

flutter_open_chinese_convert bridges OpenCC (Open Chinese Convert) to your Flutter projects.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on flutter_open_chinese_convert

Packages that implement flutter_open_chinese_convert