diff --git a/lib/api_form.dart b/lib/api_form.dart index 87acf24c..c2814d99 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -1,9 +1,10 @@ import "dart:ui"; import "dart:io"; +import "package:intl/intl.dart"; import "package:font_awesome_flutter/font_awesome_flutter.dart"; import "package:dropdown_search/dropdown_search.dart"; -import "package:date_field/date_field.dart"; +import "package:datetime_picker_formfield/datetime_picker_formfield.dart"; import "package:inventree/api.dart"; import "package:inventree/app_colors.dart"; @@ -21,7 +22,6 @@ import "package:flutter/material.dart"; import "package:inventree/widget/snacks.dart"; - /* * Class that represents a single "form field", * defined by the InvenTree API @@ -114,11 +114,11 @@ class APIFormField { dynamic get value => data["value"] ?? data["instance_value"] ?? defaultValue; // Render value to string (for form submission) - String renderToString() { - if (value == null) { + String renderValueToString() { + if (data["value"] == null) { return ""; } else { - return value.toString(); + return data["value"].toString(); } } @@ -359,22 +359,37 @@ class APIFormField { // Field for displaying and selecting dates Widget _constructDateField() { - return DateTimeFormField( - mode: DateTimeFieldPickerMode.date, + DateTime? currentDate = DateTime.tryParse((value ?? "")as String); + + return InputDecorator( decoration: InputDecoration( - helperText: helpText, - helperStyle: _helperStyle(), labelText: label, labelStyle: _labelStyle(), + helperStyle: _helperStyle(), + helperText: helpText, ), - initialValue: DateTime.tryParse((value ?? "") as String), - autovalidateMode: AutovalidateMode.disabled, - validator: (e) { - // TODO - }, - onDateSelected: (DateTime dt) { - data["value"] = dt.toString().split(" ").first; - }, + child: DateTimeField( + format: DateFormat("yyyy-MM-dd"), + initialValue: currentDate, + onChanged: (DateTime? time) { + // Save the time string + if (time == null) { + data["value"] = null; + } else { + data["value"] = time.toString().split(" ").first; + } + }, + onShowPicker: (context, value) async { + final time = await showDatePicker( + context: context, + initialDate: currentDate ?? DateTime.now(), + firstDate: DateTime(1900), + lastDate: DateTime(2100), + ); + + return time; + }, + ) ); } @@ -403,7 +418,6 @@ class APIFormField { FilePickerDialog.pickFile( message: L10().attachmentSelect, onPicked: (file) { - // print("${file.path}"); // Display the filename controller.text = file.path.split("/").last; @@ -1122,7 +1136,7 @@ class _APIFormWidgetState extends State { if (field.isSimple) { // Simple top-level field data - data[field.name] = field.renderToString(); + data[field.name] = field.data["value"]; } else { // Not so simple... (WHY DID I MAKE THE API SO COMPLEX?) if (field.parent.isNotEmpty) { @@ -1136,7 +1150,7 @@ class _APIFormWidgetState extends State { parent = parent.first; } - parent[field.name] = field.renderToString(); + parent[field.name] = field.data["value"]; // Nested fields must be handled as an array! // For now, we only allow single length nested fields diff --git a/lib/widget/home.dart b/lib/widget/home.dart index da0fabb7..c72ebcae 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -94,7 +94,7 @@ class _InvenTreeHomePageState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => PurchaseOrderListWidget() + builder: (context) => PurchaseOrderListWidget(filters: {}) ) ); } diff --git a/pubspec.lock b/pubspec.lock index 9d6d2aca..6a199be7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -127,13 +127,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.3" - date_field: + datetime_picker_formfield: dependency: "direct main" description: - name: date_field + name: datetime_picker_formfield url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.0.0" device_info_plus: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5b9a46bb..a6b94af1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: cached_network_image: ^3.1.0 # Download and cache remote images camera: # Camera cupertino_icons: ^1.0.3 - date_field: ^2.1.2 # Date / time picker + datetime_picker_formfield: ^2.0.0 # Date / time picker device_info_plus: ^2.1.0 # Information about the device dropdown_search: 0.6.3 # Dropdown autocomplete form fields file_picker: ^4.0.0 # Select files from the device