mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +00:00
Add "QuantityField"
Juicy juicy refactoring
This commit is contained in:
parent
51a877e8d7
commit
a7d11faec8
8 changed files with 102 additions and 67 deletions
26
lib/widget/fields.dart
Normal file
26
lib/widget/fields.dart
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class QuantityField extends TextFormField {
|
||||
|
||||
QuantityField({String label = "", String hint = "", double max = null, TextEditingController controller}) :
|
||||
super(
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
hintText: hint,
|
||||
),
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) return "Quantity is empty";
|
||||
|
||||
double quantity = double.tryParse(value);
|
||||
|
||||
if (quantity == null) return "Invalid quantity";
|
||||
if (quantity <= 0) return "Quantity must be positive";
|
||||
if ((max != null) && (quantity > max)) return "Quantity must not exceed ${max}";
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue