lpinyin (汉字转拼音Flutter版)
Demo: .
Android扫码下载APK
flutter_demos
Demo截图
Add dependency
dependencies:
lpinyin: x.x.x #latest version
Example
// Import package
import 'package:lpinyin/lpinyin.dart';
String text = "天府广场";
//字符串拼音首字符
PinyinHelper.getShortPinyin(str); // tfgc
//字符串首字拼音
PinyinHelper.getFirstWordPinyin(str); // tian
//无法转换拼音会 throw PinyinException
PinyinHelper.convertToPinyinString(text);
PinyinHelper.convertToPinyinString(text, separator: " ", format: PinyinFormat.WITHOUT_TONE);//tian fu guang chang
//无法转换拼音 默认用'#'替代
PinyinHelper.convertToPinyinStringWithoutException(text);
PinyinHelper.convertToPinyinStringWithoutException(text, separator: " ", defPinyin: '#', format: PinyinFormat.WITHOUT_TONE);//tian fu guang chang
//添加用户自定义字典
List<String> dict1 = ['耀=yào','老=lǎo'];
PinyinHelper.addPinyinDict(dict1);
List<String> dict2 = ['奇偶=jī,ǒu','成都=chéng,dū'];
PinyinHelper.addMultiPinyinDict(dict2);
List<String> dict3 = ['倆=俩','們=们'];
ChineseHelper.addChineseDict(dict3);