搜尋套件、儲存庫與 APP 分類

masked_text_field 封面
套件詳情v1.0.2

masked_text_field

一個用於遮罩文字欄位的套件,可格式化您的文字。如果您想要電話號碼、IP 位址或任何其他格式的遮罩,請使用此套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
656
喜歡數
29
Pub 分數
150

安裝套件

flutter pub add masked_text_field

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可實現帶有可自訂遮罩的格式化文字輸入,適用於電話號碼、IP 位址或其他結構化資料欄位。使用者輸入時會自動套用格式,確保輸入模式一致。此套件支援即時驗證,並相容所有主要平台,包括 Android、iOS、Web、macOS、Windows 與 Linux。透過強制格式,簡化表單處理並減少使用者錯誤。

適用情境

  • 電話號碼輸入
  • IP位址輸入
  • 信用卡號碼格式化
  • 日期和時間字段遮蔽
  • 自定格式輸入
  • 表單驗證協助

主要特色

  • 即時遮罩應用
  • 可設定的遮罩模式
  • 跨平台支援
  • 自動光標定位
  • 內建驗證
  • 與 TextFormField 的輕鬆整合

適合對象

  • 格式要求嚴格的表單輸入
  • 帶有資料輸入表單的手機和網路應用程式
  • 需要可重用輸入遮罩的開發人員
  • 支援國際號碼格式的應用程式
  • 以使用者體驗為導向的輸入體驗

使用建議

  • 可能需要仔細設計遮罩模式
  • 限制為文字輸入
  • 複雜遮罩可能帶來的效能影響
  • 不適用於非文字輸入類型
  • 需要手動處理焦點和選擇

原始 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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。