搜索插件、代码仓与 APP 分类

插件详情v0.4.0

language_pickers

它会为你在 Flutter 中生成语言选择器。你可以以多种方式自由使用它。

近 30 天下载
62
喜欢数
16
Pub 分数
160

安装插件

flutter pub add language_pickers

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Language Pickers 是一个 Flutter 包,可简化语言选择器的创建。它提供了预构建且可自定义的组件,用于选择语言,使应用程序的国际化实现变得轻而易举。该包设计灵活且易于集成,允许开发者在各种 UI 环境中快速实现语言选择功能。它支持多种语言,可用于表单、设置界面或任何需要语言选择的界面。该包为开源,可在个人和商业项目中免费使用。

适合场景

  • 应用本地化设置
  • 用户语言偏好选择
  • 设置屏幕语言选择器
  • 多语言表单输入
  • 国际化应用界面

主要特点

  • 预构建的语言选择器小部件
  • 可自定义的 UI 组件
  • 与 Flutter 的轻松集成
  • 支持国际化
  • 开源且免费使用

适合对象

  • 开发多语言应用程序的开发者
  • 需要语言选择工具的UI设计师
  • 需要快速实现国际化 (i18n) 的项目
  • Flutter 初学者探索选择器
  • 面向全球受众的应用

使用建议

  • 需要手动处理语言切换逻辑
  • 无内置翻译支持
  • 仅限UI选择,不涉及语言数据管理
  • 可能需要额外的软件包才能实现完整的国际化
  • 平台特定的行为未明确记录

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

language_pickers

It's package for Dart and Flutter.

It makes language select pickers for you in Flutter. You can use it freely in lots of ways.

And specially thanks to Figen Güngör(@figengungor), who is opened the source code of 'country_pickers'. Lots of source codes are from country_pickers GitHub Repository, so works are very easy. Thanks again.

Upgrading from 0.3.x

0.4.0 does not break your code. The old API still works, it only warns you. Here is what to move to:

0.3.x 0.4.0
defaultLanguagesList (List<Map<String, String>>) Languages.defaultLanguages (List<Language>)
languagesList: myMaps languages: myLanguages
LanguagePickerUtils.getLanguageByIsoCode('ko') Language.fromIsoCode('ko')
— Languages.korean, Languages.english, …

One behaviour changed: an unknown ISO code now throws an ArgumentError instead of an Exception. ArgumentError is an Error, so on Exception catch no longer catches it.

Every Language also has a nativeName now, and Language implements == and hashCode, so you can put it in a Set or use it as a Map key.

Getting Started

LanguagePickerDropdown example
import 'package:language_pickers/language_pickers.dart';

Language _selectedDropdownLanguage = Language.fromIsoCode('ko');

// It's sample code of Dropdown Item.
// nativeName is the name written in the language itself, e.g. '한국어'.
Widget _buildDropdownItem(Language language) {
  return Row(
    children: <Widget>[
      SizedBox(
        width: 8.0,
      ),
      Text("${language.name} (${language.nativeName})"),
    ],
  );
}


// Builder
LanguagePickerDropdown(
                    initialValue: 'ko',
                    itemBuilder: _buildDropdownItem,
                    onValuePicked: (Language language) {
                      _selectedDropdownLanguage = language;
                      print(_selectedDropdownLanguage.name);
                      print(_selectedDropdownLanguage.isoCode);
                    },
                  ),
Narrowing the languages down
LanguagePickerDropdown(
  languages: const <Language>[
    Languages.korean,
    Languages.english,
    Languages.japanese,
  ],
),
LanguagePickerDropdownController example

The controller lets you read and change the selection from outside the picker.

final controller =
    LanguagePickerDropdownController(initialValue: Languages.korean);

@override
void dispose() {
  controller.dispose();
  super.dispose();
}

// Builder
LanguagePickerDropdown(controller: controller),

// Somewhere else
controller.selectIsoCode('ja');   // the dropdown follows
print(controller.value.name);     // reads the current selection
LanguagePickerDialog example
import 'package:language_pickers/language_pickers.dart';

Language _selectedDialogLanguage =
      Language.fromIsoCode('ko');

// It's sample code of Dialog Item.
Widget _buildDialogItem(Language language) => Row(
    children: <Widget>[
      Text(language.name),
      SizedBox(width: 8.0),
      Flexible(child: Text("(${language.isoCode})"))
    ],
  );

void _openLanguagePickerDialog() => showDialog(
    context: context,
    builder: (context) => Theme(
        data: Theme.of(context).copyWith(primaryColor: Colors.pink),
        child: LanguagePickerDialog(
            titlePadding: EdgeInsets.all(8.0),
            searchCursorColor: Colors.pinkAccent,
            searchInputDecoration: InputDecoration(hintText: 'Search...'),
            isSearchable: true,
            title: Text('Select your language'),
            onValuePicked: (Language language) => setState(() {
                  _selectedDialogLanguage = language;
                  print(_selectedDialogLanguage.name);
                  print(_selectedDialogLanguage.isoCode);
                }),
            itemBuilder: _buildDialogItem)),
  );
LanguagePickerCupertino example
import 'package:language_pickers/language_pickers.dart';

Language _selectedCupertinoLanguage = Language.fromIsoCode('ko');

// It's sample code of Cupertino Item.
void _openCupertinoLanguagePicker() => showCupertinoModalPopup<void>(
  context: context,
  builder: (BuildContext context) {
    return LanguagePickerCupertino(
      pickerSheetHeight: 200.0,
      onValuePicked: (Language language) => setState(() {
            _selectedCupertinoLanguage = language;
            print(_selectedCupertinoLanguage.name);
            print(_selectedCupertinoLanguage.isoCode);
          }),
    );
  });

Widget _buildCupertinoItem(Language language) => Row(
    children: <Widget>[
      Text("+${language.name}"),
      SizedBox(width: 8.0),
      Flexible(child: Text(language.name))
    ],
  );

Information

If a name or a native name is wrong, please make some issues on GitHub.

The names and the native names are based on the public ISO 639-1 code table. Where the table lists several native writings for one language, this package keeps one representative writing, so that it fits in a dropdown.

Credits

Developed by gomgom(GitHub @gomgom).

所属分类

源码仓库

使用此插件的项目

暂无相关数据。