2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-07-01 11:20:41 +00:00

Format Code and Add Format Checks to CI (#643)

* Remove unused lib/generated/i18n.dart

* Use `fvm dart format .`

* Add contributing guidelines

* Enforce dart format

* Add `dart format off` directive to generated files
This commit is contained in:
Ben Hagen
2025-06-24 01:55:01 +02:00
committed by GitHub
parent e9db6532e4
commit 4444884afa
100 changed files with 5332 additions and 5592 deletions

View File

@ -9,11 +9,8 @@ import "package:one_context/one_context.dart";
import "package:inventree/l10.dart";
class FilePickerDialog {
static Future<File?> pickImageFromCamera() async {
final picker = ImagePicker();
final pickedImage = await picker.pickImage(source: ImageSource.camera);
@ -26,7 +23,6 @@ class FilePickerDialog {
}
static Future<File?> pickImageFromGallery() async {
final picker = ImagePicker();
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
@ -39,7 +35,6 @@ class FilePickerDialog {
}
static Future<File?> pickFileFromDevice() async {
final FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
@ -54,8 +49,12 @@ class FilePickerDialog {
}
// Present a dialog to pick a file, either from local file system or from camera
static Future<void> pickFile({String message = "", bool allowImages = true, bool allowFiles = true, Function(File)? onPicked}) async {
static Future<void> pickFile({
String message = "",
bool allowImages = true,
bool allowFiles = true,
Function(File)? onPicked,
}) async {
String title = "";
if (allowImages && !allowFiles) {
@ -65,16 +64,10 @@ class FilePickerDialog {
}
// Construct actions
List<Widget> actions = [
];
List<Widget> actions = [];
if (message.isNotEmpty) {
actions.add(
ListTile(
title: Text(message)
)
);
actions.add(ListTile(title: Text(message)));
}
actions.add(
@ -84,7 +77,6 @@ class FilePickerDialog {
title: Text(allowFiles ? L10().selectFile : L10().selectImage),
),
onPressed: () async {
// Close the dialog
OneContext().popDialog();
@ -101,7 +93,7 @@ class FilePickerDialog {
}
}
},
)
),
);
if (allowImages) {
@ -122,100 +114,104 @@ class FilePickerDialog {
onPicked(file);
}
}
}
)
},
),
);
}
OneContext().showDialog(
builder: (context) {
return SimpleDialog(
title: Text(title),
children: actions,
);
}
builder: (context) {
return SimpleDialog(title: Text(title), children: actions);
},
);
}
}
class CheckBoxField extends FormField<bool> {
CheckBoxField({
String? label,
bool? initial = false,
bool tristate = false,
Function(bool?)? onSaved,
TextStyle? labelStyle,
String? helperText,
TextStyle? helperStyle,
}) :
super(
onSaved: onSaved,
initialValue: initial,
builder: (FormFieldState<bool> state) {
return CheckboxListTile(
title: label != null ? Text(label, style: labelStyle) : null,
value: state.value,
tristate: tristate,
onChanged: state.didChange,
subtitle: helperText != null ? Text(helperText, style: helperStyle) : null,
contentPadding: EdgeInsets.zero,
);
}
);
String? label,
bool? initial = false,
bool tristate = false,
Function(bool?)? onSaved,
TextStyle? labelStyle,
String? helperText,
TextStyle? helperStyle,
}) : super(
onSaved: onSaved,
initialValue: initial,
builder: (FormFieldState<bool> state) {
return CheckboxListTile(
title: label != null ? Text(label, style: labelStyle) : null,
value: state.value,
tristate: tristate,
onChanged: state.didChange,
subtitle: helperText != null
? Text(helperText, style: helperStyle)
: null,
contentPadding: EdgeInsets.zero,
);
},
);
}
class StringField extends TextFormField {
StringField({
String label = "",
String? hint,
String? initial,
Function(String?)? onSaved,
Function(String?)? validator,
bool allowEmpty = false,
bool isEnabled = true,
}) : super(
decoration: InputDecoration(
labelText: allowEmpty ? label : label + "*",
hintText: hint,
),
initialValue: initial,
onSaved: onSaved,
enabled: isEnabled,
validator: (value) {
if (!allowEmpty && value != null && value.isEmpty) {
return L10().valueCannotBeEmpty;
}
StringField({String label = "", String? hint, String? initial, Function(String?)? onSaved, Function(String?)? validator, bool allowEmpty = false, bool isEnabled = true}) :
super(
decoration: InputDecoration(
labelText: allowEmpty ? label : label + "*",
hintText: hint
),
initialValue: initial,
onSaved: onSaved,
enabled: isEnabled,
validator: (value) {
if (!allowEmpty && value != null && value.isEmpty) {
return L10().valueCannotBeEmpty;
}
if (validator != null) {
return validator(value) as String?;
}
if (validator != null) {
return validator(value) as String?;
}
return null;
}
);
return null;
},
);
}
/*
* Helper class for quantity values
*/
class QuantityField extends TextFormField {
QuantityField({
String label = "",
String hint = "",
double? max,
TextEditingController? controller,
}) : super(
decoration: InputDecoration(labelText: label, hintText: hint),
controller: controller,
keyboardType: TextInputType.numberWithOptions(
signed: false,
decimal: true,
),
validator: (value) {
if (value != null && value.isEmpty) return L10().quantityEmpty;
QuantityField({String label = "", String hint = "", double? max, TextEditingController? controller}) :
super(
decoration: InputDecoration(
labelText: label,
hintText: hint,
),
controller: controller,
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
validator: (value) {
double quantity = double.tryParse(value.toString()) ?? 0;
if (value != null && value.isEmpty) return L10().quantityEmpty;
if (quantity <= 0) return L10().quantityPositive;
if ((max != null) && (quantity > max)) {
return "Quantity must not exceed ${max}";
}
double quantity = double.tryParse(value.toString()) ?? 0;
if (quantity <= 0) return L10().quantityPositive;
if ((max != null) && (quantity > max)) return "Quantity must not exceed ${max}";
return null;
},
);
}
return null;
},
);
}