mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 02:05:29 +00:00
Add API form support for date fields
This commit is contained in:
@ -3,6 +3,7 @@ import 'dart:io';
|
||||
|
||||
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:inventree/api.dart';
|
||||
import 'package:inventree/app_colors.dart';
|
||||
@ -167,6 +168,8 @@ class APIFormField {
|
||||
case "file upload":
|
||||
case "image upload":
|
||||
return _constructFileField();
|
||||
case "date":
|
||||
return _constructDateField();
|
||||
default:
|
||||
return ListTile(
|
||||
title: Text(
|
||||
@ -179,6 +182,30 @@ class APIFormField {
|
||||
}
|
||||
}
|
||||
|
||||
// Field for displaying and selecting dates
|
||||
Widget _constructDateField() {
|
||||
|
||||
return DateTimeFormField(
|
||||
mode: DateTimeFieldPickerMode.date,
|
||||
decoration: InputDecoration(
|
||||
helperText: helpText,
|
||||
helperStyle: _helperStyle(),
|
||||
labelText: label,
|
||||
labelStyle: _labelStyle(),
|
||||
),
|
||||
initialValue: DateTime.tryParse(value ?? ""),
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
validator: (e) {
|
||||
// TODO
|
||||
},
|
||||
onDateSelected: (DateTime dt) {
|
||||
data['value'] = dt.toString().split(" ").first;
|
||||
},
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Field for selecting and uploading files
|
||||
Widget _constructFileField() {
|
||||
|
||||
@ -418,6 +445,13 @@ class APIFormField {
|
||||
style: TextStyle(fontWeight: selected ? FontWeight.bold : FontWeight.normal),
|
||||
) : null,
|
||||
);
|
||||
case "owner":
|
||||
String name = item["name"] ?? "";
|
||||
bool isGroup = (item["label"] ?? "") == "group";
|
||||
return ListTile(
|
||||
title: Text(name),
|
||||
leading: FaIcon(isGroup ? FontAwesomeIcons.users : FontAwesomeIcons.user),
|
||||
);
|
||||
default:
|
||||
return ListTile(
|
||||
title: Text(
|
||||
|
Reference in New Issue
Block a user