45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:component_library/component_library.dart';
|
|
import 'package:reactive_forms/reactive_forms.dart';
|
|
|
|
import 'error_messages.dart';
|
|
|
|
class ReactiveInputFile extends ReactiveFormField<List<File>, List<File>> {
|
|
ReactiveInputFile({
|
|
required String name,
|
|
allowMultiple = false,
|
|
allowedExtensions = const ['jpg', 'jpeg', 'png', 'gif'],
|
|
uploadButtonLabel,
|
|
guidanceLabel,
|
|
descriptionLabel,
|
|
}) : super(
|
|
formControlName: name,
|
|
builder: (field) {
|
|
return InputFile(
|
|
files: field.value,
|
|
allowMultiple: allowMultiple,
|
|
descriptionLabel: descriptionLabel,
|
|
guidanceLabel: guidanceLabel,
|
|
uploadButtonLabel: uploadButtonLabel,
|
|
allowedExtensions: allowedExtensions,
|
|
errorMessage: ErrorMessages.getUiErrorMessage(
|
|
control: field.control,
|
|
label: '',
|
|
widgetCustomMessages: {'required': 'Foto harus diisi'},
|
|
),
|
|
isTouched: field.control.touched,
|
|
isError: field.control.hasErrors,
|
|
onChange: (files) {
|
|
field.didChange(files);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
|
|
@override
|
|
ReactiveFormFieldState<List<File>, List<File>> createState() {
|
|
return ReactiveFormFieldState<List<File>, List<File>>();
|
|
}
|
|
}
|