flutter_open_chinese_convert 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

flutter_open_chinese_convert #

flutter_open_chinese_convert bridges OpenCC (開放中文轉換) to your Flutter projects. You can use the package to convert Traditional Chinese to Simplified Chinese, and vise versa.

The package supports various conversion options:

  • S2T: Simplified Chinese to Traditional Chinese.
  • T2S: Traditional Chinese to Simplified Chinese.
  • S2HK: Simplified Chinese to Traditional Chinese (Hong Kong Standard).
  • HK2S: Traditional Chinese (Hong Kong Standard) to Simplified Chinese.
  • S2TW: Simplified Chinese to Traditional Chinese (Taiwan Standard).
  • TW2S: Traditional Chinese (Taiwan Standard) to Simplified Chinese.
  • S2TWp: Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom.
  • TW2Sp: Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom.

Usage #

All you need to do is to call ChineseConverter.convert with what you wan to convert and a conversion option. For exaple:

import 'package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart';

var text = '鼠标里面的硅二极管坏了,导致光标分辨率降低。';
var result = await ChineseConverter.convert(text, S2TWp());
// 滑鼠裡面的矽二極體壞了,導致游標解析度降低。

For further information, please visit:

0.2.1 #

  • Updates format of the pubspec.yaml file.

0.2.0 #

  • Makes it able to create native threads for text conversion.

0.1.1 #

  • Updates dependencies.

0.1.0 #

  • Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart';
import 'package:twicon/twicon.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _index = 0;
  String _original = '鼠标里面的硅二极管坏了,导致光标分辨率降低。\n滑鼠裡面的矽二極體壞了,導致游標解析度降低。';
  String _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: Row(
            children: <Widget>[
              Icon(TaiwanIcons.tapioca_milk_tea),
              const Text('Open Chinese Convert'),
            ],
          )),
          body: SafeArea(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                buildMenu(context),
                Divider(),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text('Original:',
                      style: Theme.of(context).textTheme.title),
                ),
                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.title),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(_converted ?? ''),
                ),
              ],
            ),
          ),
        ),
      );

  Widget buildMenu(BuildContext context) => PopupMenuButton<int>(
      elevation: 2,
      child: Container(
        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(
                child: Row(
                  children: <Widget>[
                    Container(
                        width: 40,
                        child: i == _index ? Icon(Icons.check) : Container()),
                    Expanded(
                        child: Text(x.chineseDescription,
                            style: TextStyle(fontSize: 12.0))),
                  ],
                ),
                value: i,
              )))
          .values));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_open_chinese_convert: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:flutter_open_chinese_convert/flutter_open_chinese_convert.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • flutter_open_chinese_convert that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test
pedantic ^1.8.0