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

masked_text_field のカバー
パッケージ詳細v1.0.2

masked_text_field

テキストをフォーマットするためのマスク付きテキストフィールド用パッケージです。電話番号やIPアドレス、または他の形式のマスクが必要な場合は、このパッケージを使用してください。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
656
いいね数
29
Pub ポイント
150

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

flutter pub add masked_text_field

パッケージ概要

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

電話番号やIPアドレス、その他の構造化データのようなフィールドに最適な、カスタマイズ可能なマスクを使用したフォーマットされたテキスト入力を可能にするFlutterパッケージです。ユーザーが入力する際に自動的にフォーマットを適用し、一貫した入力パターンを保証します。リアルタイムの検証をサポートしており、Android、iOS、Web、macOS、Windows、Linuxなどすべての主要プラットフォームと互換性があります。強制的なフォーマットにより、ユーザーの入力エラーを減らし、フォーム処理を簡素化します。

用途

  • 電話番号入力
  • IPアドレスの入力
  • クレジットカード番号の書式設定
  • 日付と時刻フィールドのマスキング
  • カスタムフォーマット入力
  • フォーム検証の支援

主な機能

  • リアルタイムマスク適用
  • カスタマイズ可能なマスクパターン
  • クロスプラットフォーム対応
  • カーソルの自動位置合わせ
  • 組み込み検証
  • TextFormField との簡単な統合

適している対象

  • 厳格なフォーマットを必要とするフォーム入力
  • データ入力フォームを備えたモバイルおよびウェブアプリケーション
  • 再利用可能な入力マスクが必要な開発者
  • 国際番号形式に対応したアプリ
  • UXに焦点を当てた入力体験

注意事項

  • マスクパターンの設計に注意が必要な場合があります
  • テキストベースの入力に制限
  • 複雑なマスクによるパフォーマンスへの潜在的な影響
  • テキスト以外の入力タイプには適していません
  • フォーカスと選択の手動処理が必要

元の README

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

Masked Text Field

Masked Text Field

pub package pub points LinkedIn Instagram Facebook Youtube

Features

A package for masked text field for format your text (eg. Date, phone number, IP address etc.), so if you want a mask for phone number, or IP address or any kind of format. Use this package.
Image

Getting started

Add the dependency in pubsec.yaml file.

dart
  dependencies:
    flutter:
      sdk: flutter
    masked_text_field: any

Usage Example

import flutter_social_button.dart


import 'package:masked_text_field/masked_text_field.dart';

for add Text Field

It's very simple, it's a Widget as all the other ones.


MaskedTextField
(
    maskedTextFieldController: textfieldController,
    mask: "xxx.xxx.xxx.xxx",
    maxLength: 15,
    keyboardType: TextInputType.number,
    inputDecoration: new InputDecoration(
    hintText: "192.192.192.192", 
    counterText: "",
    labelText: "IP Address"),
);

'x' is the normal char that your text will have.

this sample reproduces something like this in the end: 192.192.192.192.

You can also change the escape character you want to use.

If you want to change it, you just need to fill the property escapeCharacter with the character you want.


MaskedTextField
(
    maskedTextFieldController: textfieldController,
    escapeCharacter: '#',
    mask: "###.###.###.###",
    maxLength: 15,
    keyboardType: TextInputType.number,
    inputDecoration: new InputDecoration(
    counterText: "",
    hintText: "192.192.192.192", 
    labelText: "IP Address"),
);

'x' is the default escape character.

Example


import 'package:flutter/material.dart';
import 'package:masked_text_field/masked_text_field.dart';

void main() {
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(title: 'Masked Text Field'),
    );
  }
}

class HomePage extends StatefulWidget {
  final String title;
  const HomePage({Key? key, required this.title}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  var ipController = TextEditingController();
  var dateController = TextEditingController();
  var phoneController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text('Enter IP Address'),
            const SizedBox(height: 5,),
            MaskedTextField(
              textFieldController: ipController,
              inputDecoration: const InputDecoration(
                hintText: '192.192.192.192',
                  counterText: ""
              ),
              autofocus: true,
              mask: 'xxx.xxx.xxx.xxx',
              maxLength: 15,
              keyboardType: TextInputType.number,
              onChange: (String value) {
                print(value);
              },
            ),
            const SizedBox(height: 10,),
            const Text('Enter Date'),
            const SizedBox(height: 5,),
            MaskedTextField(
              textFieldController: dateController,
              inputDecoration: const InputDecoration(
                  hintText: 'DD/MM/YYYY',
                  counterText: ""
              ),
              autofocus: true,
              mask: 'xx/xx/xxxx',
              maxLength: 10,
              keyboardType: TextInputType.number,
              onChange: (String value) {
                print(value);
              },
            ),
            const SizedBox(height: 10,),
            const Text('Enter Phone Number'),
            const SizedBox(height: 5,),
            MaskedTextField(
              textFieldController: phoneController,
              inputDecoration: const InputDecoration(
                  hintText: '98765-43210',
                  counterText: "",
                prefixText: '+91 ',
              ),
              autofocus: true,
              mask: 'xxxxx-xxxxx',
              maxLength: 11,
              keyboardType: TextInputType.number,
              onChange: (String value) {
                print(value);
              },
            ),
          ],
        ),
      ),
    );
  }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

カテゴリー

ソースリポジトリ

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

データはまだありません。