パッケージ、リポジトリ、アプリカテゴリを検索

textfield_tags のカバー
パッケージ詳細v3.0.1

textfield_tags

テキストフィールド内でタグの入力を許可するテキストフィールド

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.4万
いいね数
420
Pub ポイント
160

パッケージをインストール

flutter pub add textfield_tags

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Flutterパッケージで、ユーザーがテキストフィールド内でタグの入力と管理を直接行えるようにします。動的にタグの追加・編集・削除ができる直感的なインターフェースを提供し、視覚的なフィードバックによりフォームのインタラクションを強化します。ノートやソーシャルメディア、タスク管理ツールにおけるタグシステムなど、キーワードまたはカテゴリの入力を必要とするアプリケーションに最適です。Android、iOS、Web、macOS、Windows、Linuxなど複数のプラットフォームをサポートしており、デバイス間での動作の一貫性を確保しています。

用途

  • ユーザー入力をタグ付けする
  • 動的キーワードを含むフォームフィールド
  • ソーシャルメディア投稿タグ付け
  • タスクまたはプロジェクトのカテゴリ化
  • タグの提案付き検索フィルター

主な機能

  • インラインタグの作成
  • カスタマイズ可能なタグスタイル
  • クロスプラットフォーム対応
  • 既存のフォームとの簡単な統合
  • リアルタイムタグ管理

適している対象

  • インタラクティブなフォームを構築する開発者
  • キーワードタグが必要なアプリ
  • マルチプラットフォームアプリケーション
  • 動的コンテンツ入力を持つ UI

注意事項

  • タグ制限の慎重な取り扱いが必要です
  • カスタム検証ロジックが必要になる場合があります
  • 多数のタグでのパフォーマンス
  • 限定された組み込みの自動補完機能
  • スタイリングのカスタマイズには追加のコードが必要になる場合があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

textfield_tags

Textfield_tags is a widget that allows developers to create tags inside a textfield. The widget comes with 2 default controllers that allow you to store tags as regular strings or objects. Alternatively, you can create your own controller by extending the base controller class to have custom tag controllers.

Environment

sdk: ">=2.12.0 <4.0.0"

flutter: ">=1.17.0"

Installation

  dependencies:
      textfield_tags: ^3.0.1

$ flutter pub get

Getting Started

To get started using this widget, you will need to first import the package inside your project following the installation guide found on Flutter.dev.

Usage

To use this widget,

  1. import 'package:textfield_tags/textfield_tags.dart'; inside your dart file
  2. Follow one of the examples bellow and call the widget TextFieldTags(...).
  3. The widget takes in 9 arguments: List<String>? initialTags, ScrollController? scrollController, FocusNode? focusNode, TextEditingController? textEditingController, List<String>? textSeperators, LetterCase? letterCase, Validator? validator, InputFieldBuilder inputfieldBuilder, TextfieldTagsController? textfieldController.

Read the api documentation on these properties for more details or see the examples provided in the example folder.

Examples With Different Controllers

By default, the widget comes with 2 built-in controllers: one that allows you to manage string type tags and another one that allows you to use any type of tags including objects, ints, strings, etc. We will show examples of the two controllers in actions bellow.

Using String type tags (StringTagControlle)

If you only want to use string based tags, then the StringTagController is ideal for you. The example bellow shows how you can utilize the StringTagController<String>() controller to manage string tags.

See Full Example

  class MyWidget extends StatelessWidget {
    const MyWidget({Key? key}) : super(key: key);

    final _stringTagController = StringTagController();

    @override
    Widget build(BuildContext context) {
      return TextFieldTags<String>(
        textfieldTagsController: _stringTagController,
        initialTags:['python','java'],
        textSeparators: const [' ', ','],
        validator: (String tag){
          if (tag == 'php'){
            return 'Php not allowed';
          }
          return null;
        },
        inputFieldBuilder: (context, inputFieldValues){
          return TextField(
            controller: inputFieldValues.textEditingController,
            focusNode: inputFieldValues.focusNode, 
          );
        }
      );
    }
  }

Using dynamic tags (DynamicTagController)

If you want to store dynamic type of datas with each tags, then using DyanmicTagController will be ideal for you. This will offer you more flexibiliity and customization and will allow you to design the tags based on their own stored data.

See Full Example

//Sample data model 
class ButtonData {
  final Color buttonColor;
  final String emoji;
  const ButtonData(this.buttonColor, this.emoji);
}

class MyWidget extends StatelessWidget {
    const MyWidget({Key? key}) : super(key: key);
    final _dynamicTagController = DynamicTagController<TagData<ButtonData>>()

    @override
    Widget build(BuildContext context) {
      return TextFieldTags<DynamicTagData<ButtonData>>(
        textfieldTagsController: _dynamicTagController,
        initialTags:[
          DynamicTagData<ButtonData>(
            'cat',
            const ButtonData(
              Color.fromARGB(255, 132, 204, 255),
              "😽",
            ),
          ),
          DynamicTagData<ButtonData>(
            'penguin',
            const ButtonData<ButtonData>(
              Color.fromARGB(255, 255, 131, 228),
              '🐧',
            ),
          ),
          DynamicTagData<ButtonData>(
            'tiger',
            const ButtonData(
              Color.fromARGB(255, 222, 255, 132),
              '🐯',
            ),
          ),
        ],
        textSeparators: const [' ', ','],
        validator: (DynamicTagData<ButtonData> tag){
          if (tag.tag == 'lion') {
            return 'Not envited per tiger request';
          } else if (_dynamicTagController.getTags!
              .any((element) => element.tag == tag.tag)) {
            return 'Already in the club';
          }
          return null;
        },
        inputFieldBuilder: (context, inputFieldValues){
          return TextField(
            controller: inputFieldValues.textEditingController,
            focusNode: inputFieldValues.focusNode,
          );
        }
      ); 
    }
  }

More Advanced Functionality Via A Custom Controller

If you feel like you want more functionality than what is offered by the 2 default controllers, then you can easily extend TextfieldTagsController class to your own custom class and inherit all its functionalities and add your own stuffs as bellow example shows.

The bellow example shows you how you can use a numbers tag picker that selects numbers between 2 and 10 with the exception of number 8.

See Full Example

  // Create my own custom controller
  class MyIntTagController<T extends int> extends TextfieldTagsController<T> {
      @override
      bool? onTagSubmitted(T value) {
          String? validate = getValidator != null ? getValidator!(value) : null;
          if (validate == null && value > 2 && value < 10) {
            bool? addTag = super.addTag(value);
            if (addTag == true) {
              setError = null;
              scrollTags();
            }
          } else if (validate != null) {
            setError = validate;
          } else {
            setError = 'Must enter numbers between 2 and 10';
          }
          return null;
      }

      @override
      set setError(String? error) {
        super.setError = error;
        notifyListeners();
      }

      doOtherThings(){
        ...
      }
  }

  class MyWidget extends StatelessWidget {
    const MyWidget({Key? key}) : super(key: key);
    final _myintTagController = MyIntTagController<int>();

    @override
    Widget build(BuildContext context) {
      return TextFieldTags<int>(
        textfieldTagsController: _myintTagController,
        initialTags:[ 4, 5 ],
        validator: (int tag){
          if (tag == 8){
            return '8 is not allowed';
          }
          return null;
        },
        inputFieldBuilder: (context, inputFieldValues){
          return TextField(
            controller: inputFieldValues.textEditingController,
            focusNode: inputFieldValues.focusNode,
          );
        }
      ); 
    }
  }

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト