File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change
1
+ extension GenericValidator <T > on T ? {
2
+ bool emptyValidator () {
3
+ if (this == null ) return true ;
4
+ if (this is Iterable ) return (this as Iterable ).isEmpty;
5
+ if (this is String ) return (this as String ).isEmpty;
6
+ if (this is List ) return (this as List ).isEmpty;
7
+ if (this is Map ) return (this as Map ).isEmpty;
8
+ if (this is Set ) return (this as Set ).isEmpty;
9
+ return false ;
10
+ }
11
+ }
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/foundation.dart' ;
2
2
import 'package:flutter/material.dart' ;
3
3
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
4
+ import 'package:flutter_form_builder/src/extensions/generic_validator.dart' ;
4
5
5
6
/// Field for Dropdown button
6
7
class FormBuilderDropdown <T > extends FormBuilderFieldDecoration <T > {
@@ -309,19 +310,9 @@ class _FormBuilderDropdownState<T>
309
310
310
311
if ((! listEquals (oldChilds, currentlyChilds) ||
311
312
! listEquals (oldValues, currentlyValues)) &&
312
- (widget.items .contains (initialValue) ||
313
- _emptyValidator < T >( initialValue))) {
313
+ (currentlyValues .contains (initialValue) ||
314
+ initialValue. emptyValidator ( ))) {
314
315
setValue (initialValue);
315
316
}
316
317
}
317
318
}
318
-
319
- bool _emptyValidator <T >(T ? value) {
320
- if (value == null ) return true ;
321
- if (value is Iterable ) return value.isEmpty;
322
- if (value is String ) return value.isEmpty;
323
- if (value is List ) return value.isEmpty;
324
- if (value is Map ) return value.isEmpty;
325
- if (value is Set ) return value.isEmpty;
326
- return false ;
327
- }
You can’t perform that action at this time.
0 commit comments