Giter Club home page Giter Club logo

input-quantity's Introduction

Input Quantity

pub package likes popularity pub points package 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

Usage

  • example:
import 'package:input_quantity/input_quantity.dart';
...
  InputQty(
    maxVal: 100,
    initVal: 0,
    minVal: -100,
    steps: 10,
    onQtyChanged: (val) {
      print(val);
    },
  ),

Typing manual

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

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

Output

By default, the output will be as a num.

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

in v1, we need to parse the output back to int or double inside onChange. Now from v2, you can specify the output.

as int

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

or as double

InputQty.double(
  onQtyChanged: (val) {
      print(val.runType);// double
    },
)

The position and orientation of the button

by default will be set as classic mode. Which is the plus button on the right and the minus button on the left

InputQty(
   decoration: const QtyDecorationProps(
          qtyStyle: QtyStyle.classic
   )
)

Put the button on the left :

InputQty(
   decoration: const QtyDecorationProps(
       qtyStyle: QtyStyle.btnOnLeft
       orientation: ButtonOrientation.horizontal
   )
)

last choice, on the right side

InputQty(
   decoration: const QtyDecorationProps(
      qtyStyle: QtyStyle.btnOnRight
      orientation: ButtonOrientation.vertical
   )
)

For other example styling, you may check on the example page

Image Preview

To Do

  • Add more documentation
  • Splash effect
  • Export icon decoration
  • Add more example

Additional information

  • To contribute to this project, you can open a PR or an issue.

  • Want to thank me? you can buy me a coffee

input-quantity's People

Contributors

pmatatias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

input-quantity's Issues

Overflow when step is a double type

I encountered the problem that when I set step = 0.1, the value will overflow sometimes.

For example, 0.1 + 0.1 = 0.20000000001. Is there any way to round off the value shown in the UI?

Button Icons used are not configurable

Hi @pmatatias
Thank you for your library, it is great! I do, however, need one small change - I need to configure the icons.
Now I can set my own widget for the icons, but then my widget overrides the one that is working and the colors don't change. I have forked the project and have created a branch to implement this change without affecting the existing functionality.

Please see the branch below, if everything is in order, can I create a pull request?

skynamo/input-quantity

Throw exception when set `isIntrinsicWidth: false`

This error thow when wrap the InputQty inside Column or Row widget. This is because the TextFormField will wrapped with Expanded widget.

โ•โ•โ•โ•โ•โ•โ•โ• Exception caught by rendering library โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
RenderBox was not laid out: RenderFlex#93e71 relayoutBoundary=up25 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
package:flutter/โ€ฆ/rendering/box.dart:1
Failed assertion: line 2001 pos 12: 'hasSize'

The relevant error-causing widget was
InputQty
lib\production_wo_detail.dart:404
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

outline border color and width does not working

InputQty.double(
decoration: QtyDecorationProps(
contentPadding: EdgeInsets.symmetric(
vertical: context.dynamicHeight(6),
horizontal: context.dynamicWidth(2),
),
isBordered: false,
border: OutlineInputBorder(
borderSide: BorderSide(
width: 10, color: Colors.red),
borderRadius:
BorderRadius.circular(10))),
initVal: product.quantityLocal.toDouble(),
onQtyChanged: (value) {
setState(() {
product.quantityLocal = value.toInt();
});
},
)

                                in that case the color and width does not working

How about setting value outside widget?

In my case i getting new value from another place (for example: websocket)
And setting value as initVal has no effect

How set new value outside? (Something like controller?)

Is it possible to specify type of `onQtyChanged` ?

Currently I used ValueChanged?, which the function will return dynmic. even use InputQty.int the value actually int but the parameter of the onQtyChanged is dynamic value.

I had do some experiment by declare inside constructor. but then i can call it inside state class. Please take a look at this question on Stakoverflow: https://stackoverflow.com/q/77158813/12838877

My experiment can found on branch update-onChange :
https://github.com/pmatatias/input-quantity/tree/update-onChange

Improve regex pattern for Input formatters

In the current version, I use this format (line 286)
this format work fine for:

  • type decimal numbers
  • negative and positive number
  • avoid more than 2 zeros in the front and allow multiple zeros after the decimal point
inputFormatters: [
  FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\-?\d*')),
],

but there is an issue occurred :
found issue:

  • negative sign after number: #23
    the input can be like 5-5. this should be not allowed. the - sign should only be available in the front.

case that needs to cover:

  • keyboard allowed: numbers 0-9, and some characters: dot (.), plus sign ( + ), and negative sign (-)
  • allow decimal numbers: 1.3, 2.4. etc
  • special for zero in the front: 0.3 and .3 are the same value.
  • avoid more than 2 zeros in the front: 000.3 โŒ
  • We can type a positive sign in the front: example: +23
  • We can type a negative sign in the front: example: -54
  • Negative and positive sign only in the front: related to PR: #23

example test:

number result
23 โœ”๏ธ
+23 โœ”๏ธ
-23 โœ”๏ธ
0.4 โœ”๏ธ
.4 โœ”๏ธ
00.4 โŒ
0.04 โœ”๏ธ
0.405 โœ”๏ธ
47-7 โŒ
45+43 โŒ
054 โŒ
5009 โœ”๏ธ
0008 โŒ
-0.45 โœ”๏ธ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.