搜尋套件、儲存庫與 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).

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。