|
1 |
| -import 'dart:io'; |
2 |
| - |
3 | 1 | import 'package:flutter/material.dart';
|
4 | 2 | import '../form_builder_validators.dart';
|
5 | 3 |
|
@@ -445,31 +443,31 @@ class FormBuilderValidators {
|
445 | 443 | : null;
|
446 | 444 |
|
447 | 445 | /// [FormFieldValidator] that requires the field's value to be a valid file extension.
|
448 |
| - static FormFieldValidator<File> fileExtension({ |
| 446 | + static FormFieldValidator<String> fileExtension({ |
449 | 447 | required List<String> allowedExtensions,
|
450 | 448 | String? errorText,
|
451 | 449 | }) =>
|
452 |
| - (File? valueCandidate) => valueCandidate == null |
| 450 | + (valueCandidate) => valueCandidate == null |
453 | 451 | ? null
|
454 |
| - : !allowedExtensions.contains( |
455 |
| - fileExtensionFromPath(valueCandidate.path).toLowerCase()) |
| 452 | + : !allowedExtensions |
| 453 | + .contains(fileExtensionFromPath(valueCandidate).toLowerCase()) |
456 | 454 | ? errorText ??
|
457 | 455 | FormBuilderLocalizations.current
|
458 | 456 | .fileExtensionErrorText(allowedExtensions.join(', '))
|
459 | 457 | : null;
|
460 | 458 |
|
461 | 459 | /// [FormFieldValidator] that restricts the size of an file to be less than or equal to the provided maximum size.
|
462 | 460 | /// * [maxSize] is the maximum size in bytes.
|
463 |
| - static FormFieldValidator<File> fileSize({ |
| 461 | + static FormFieldValidator<String> fileSize({ |
464 | 462 | required int maxSize,
|
465 | 463 | String? errorText,
|
466 | 464 | }) =>
|
467 |
| - (File? valueCandidate) => valueCandidate == null |
| 465 | + (valueCandidate) => valueCandidate == null |
468 | 466 | ? null
|
469 |
| - : valueCandidate.existsSync() && valueCandidate.lengthSync() > maxSize |
| 467 | + : int.parse(valueCandidate) > maxSize |
470 | 468 | ? errorText ??
|
471 | 469 | FormBuilderLocalizations.current.fileSizeErrorText(
|
472 |
| - formatBytes(valueCandidate.lengthSync()), |
| 470 | + formatBytes(int.parse(valueCandidate)), |
473 | 471 | formatBytes(maxSize),
|
474 | 472 | )
|
475 | 473 | : null;
|
|
0 commit comments