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

input_quantity 封面
套件詳情v2.6.0

input_quantity

一個用於輸入數量的小部件。使用 TextFormField 建構。可手動輸入,也可透過按鈕增加或減少數值。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3880
喜歡數
76
Pub 分數
160

安裝套件

flutter pub add input_quantity

套件介紹

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

一個用於輸入數量的 Flutter 小部件,結合了文字欄位與增減按鈕。使用者可手動輸入數值,或使用提供的按鈕進行調整,確保直覺且易於存取的數字輸入體驗。基於 TextFormField 建構,支援標準文字輸入行為,同時提升數量選擇的可用性。適用於需要數字輸入的表單,例如購物車或設定介面。

適用情境

  • 電商商品數量選擇
  • 需要數值的表單輸入
  • 庫存管理介面
  • 使用者偏好設定
  • 訂單輸入系統

主要特色

  • 內建的增減按鈕
  • 手動文字輸入支援
  • 可自訂步長
  • 跨平台的響應式設計
  • 與 TextFormField 的整合

適合對象

  • 簡單數量輸入
  • 行動與Web應用程式
  • 包含數字欄位的表單
  • 尋求輕量級旋轉框的開發者
  • 需要最少設定的應用程式

使用建議

  • 僅限基本數字輸入
  • 除了文字輸入外,沒有內建驗證
  • 需要手動處理最小值/最大值約束
  • 不適用於複數格式化
  • 依賴外部樣式來呈現外觀

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Input Quantity

Get it on Google Play

pub pkg likes Popularity Pub points Publisher Star on Github License: MIT

Flutter widget for quantity input. Increase or decrease the input value by pressing the button. It's built with text fields, so InputQty also supports manually typing quantities. Very flexible for large quantities. For example, if the user wants to enter the value 19243, it will be very difficult to only rely on buttons.

Set input limits so that input values automatically return to predefined maximum/minimum values.

Demo Preview

Features

  • Simple and easy to use
  • Customizable
  • Output: int, double, or num
  • Style options: classic, button on the left or button on the right
  • Tap once to update the value, longpress for update the value continuously, or type the value manually.
  • Add validator form, or use custom message builder

Installation

To use this package, add input_quantity as a dependency in your pubspec.yaml file.

dependencies:
  input_quantity: ^2.5.0

Then, run flutter pub get to install the package.

Usage

Basic Usage
import 'package:input_quantity/input_quantity.dart';

InputQty(
  maxVal: 100,
  initVal: 0,
  minVal: -100,
  steps: 10,
  onQtyChanged: (val) {
    print(val);
  },
)
Typing Manually

If you want to prevent typing manually, you can disable it from enableTyping.

InputQty(
  qtyFormProps: QtyFormProps(enableTyping: false),
  ...
)
Output Types

By default, the output will be as a num.

InputQty(
  onQtyChanged: (val) {
    print(val.runtimeType); // num
  },
)

To specify the output type as int:

InputQty.int(
  onQtyChanged: (val) {
    print(val.runtimeType); // int
  },
)

To specify the output type as double:

InputQty.double(
  onQtyChanged: (val) {
    print(val.runtimeType); // double
  },
)
Customizing Appearance and Behavior
Using QtyFormProps

You can customize the appearance and behavior of the input field using QtyFormProps.

InputQty(
  qtyFormProps: QtyFormProps(
    textAlign: TextAlign.center,
    style: TextStyle(fontWeight: FontWeight.bold),
    cursorColor: Colors.red,
    enableTyping: true,
  ),
)
Using QtyDecorationProps

You can customize the decoration of the input field using QtyDecorationProps.

InputQty(
  decoration: QtyDecorationProps(
    borderShape: BorderShapeBtn.circle,
    btnColor: Colors.blue,
    fillColor: Colors.grey[200],
    isBordered: true,+
  ),
)
Validation

You can use the validator property to validate the input value.

InputQty(
  validator: (value) {
    if (value == null) {
      return "Required field";
    } else if (value >= 200) {
      return "More than available quantity";
    }
    return null;
  },
)
Custom Messages

You can use the messageBuilder property to display custom messages based on the input value.

InputQty(
  messageBuilder: (minVal, maxVal, value) {
    if (value == null) return null;
    if (value < -20) {
      return Text(
        "Reach my limit",
        style: TextStyle(color: Colors.red),
        textAlign: TextAlign.center,
      );
    } else if (value > 20) {
      return Text(
        "Reach my limit",
        style: TextStyle(color: Colors.red),
        textAlign: TextAlign.center,
      );
    } else {
      return Text("Value : $value", textAlign: TextAlign.center);
    }
  },
)
Controlling Input Value Programmatically

You can use TextEditingController to control the input value programmatically.

final TextEditingController _controller = TextEditingController();

InputQty(
  qtyFormProps: QtyFormProps(
    controller: _controller,
  ),
)
Button Orientation

You can change the orientation of the buttons using ButtonOrientation.

InputQty(
  decoration: QtyDecorationProps(
    orientation: ButtonOrientation.horizontal,
  ),
)
Button Position

You can change the position of the buttons using QtyStyle.

InputQty(
  decoration: QtyDecorationProps(
    qtyStyle: QtyStyle.btnOnRight,
  ),
)

Examples

For more examples, check the example directory.

Image Preview

Contributons

To contribute to this project, please follow the guidelines in the CONTRIBUTING.md file.

Thank you to all contributors for their valuable contributions!

@pmatatias @tonypioneer @fixiply @sirfaman @daniel-pimenta-cc @5amfung

Additional Information

  • Want to thank me? You can buy me a coffee.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。