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 11import 'package:flutter/foundation.dart' ;
22import 'package:flutter/material.dart' ;
33import 'package:flutter_form_builder/flutter_form_builder.dart' ;
4+ import 'package:flutter_form_builder/src/extensions/generic_validator.dart' ;
45
56/// Field for Dropdown button
67class FormBuilderDropdown <T > extends FormBuilderFieldDecoration <T > {
@@ -309,19 +310,9 @@ class _FormBuilderDropdownState<T>
309310
310311 if ((! listEquals (oldChilds, currentlyChilds) ||
311312 ! listEquals (oldValues, currentlyValues)) &&
312- (widget.items .contains (initialValue) ||
313- _emptyValidator < T >( initialValue))) {
313+ (currentlyValues .contains (initialValue) ||
314+ initialValue. emptyValidator ( ))) {
314315 setValue (initialValue);
315316 }
316317 }
317318}
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