-
-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange error in FormBuilderDropdown #61
Comments
Hi @shariful2011, You could avoid this assertion fail by having |
I update as per you said but still same error. I did check if the items is null or not so why still the exception. Please see the image http://prntscr.com/nqnd0h |
Kindly paste your updated code |
Widget districtDropDown( |
Unfortunately, I'm unable to reproduce your issue - when I make the Try restarting your app instead of hot reload. |
Problem is not with initialValue, See the error: I did a test by restarting the app. The problem occurs only on the 3rd DropDown when it has selected item. |
Kindly note first that the error is from the underlying Flutter's Here's what I understand from the error. The dropdown tries to assert that either of these conditions are met.
Is it possible for you to share more code - especially the part where you are calling the |
class DistrictDropDown extends StatelessWidget { @OverRide Future<List> getAllDistrict(int governorateid) async { |
Please see the video https://mega.nz/#!uttGgCDY!ipUCrFw5zarVAqClZaQmtnC21Y2XH5XDpHkv6aUSHUc from which you can undrstand. |
Sorry for the late response. Timezone issues. I've seen the video. Does your District options change depending on the Governorate dropdown? |
Yes, as I said all my dropdown are interlinked. |
@shariful2011 - if your dropdown item list is changed depend on other form field, I think you should use FormBuilderCustomField instead just like in the readme description. |
Here's what's happening in your specific scenario: Since your list of options will change at runtime, there will be a point in time where option you already selected is not part of the newly available options that's the point where the assertion will fail.
Point to note: Your error in an assertion error which essentially means it will be ignored in production, you can choose to ignore it during development. Another option you have is that before changing the Governorate, make sure nothing is selected in District. Last point - This is not an assertion failure on Flutter's underlying |
How can I make sure nothing is selected in District? Is there an option to clear it? |
I have 3 FormBuilderDropdown which's item are filling from the database. They are totally linked. Like:
My Scope is if Country selected it will refresh all FormBuilderDropdown.
Not getting any exception until I select a data on 3rd FormBuilderDropdown that is the District. If I not selecting any data on that FormBuilderDropdown nothing is raising, but when I change any Governorate FormBuilderDropdown I got following exception but I still have items for the District FormBuilderDropdown which is 5 as print. This is my code:
Widget districtDropDown(
{ValueChanged changed,
List<DropdownMenuItem> items,
String attribute}) {
print('district=${items.length}');
return items.length == 0
? FormBuilderDropdown(
attribute: attribute,
hint: Text('Select District'),
onChanged: changed,
decoration: InputDecoration(
labelText: 'District',
labelStyle: TextStyle(
fontFamily: 'Open Sans',
),
),
validators: [
FormBuilderValidators.required(
errorText: 'Please select District.'),
],
initialValue: '',
items: [],
)
: FormBuilderDropdown(
attribute: attribute,
hint: Text('Select District'),
onChanged: changed,
decoration: InputDecoration(
labelText: 'District',
labelStyle: TextStyle(
fontFamily: 'Open Sans',
),
),
validators: [
FormBuilderValidators.required(
errorText: 'Please select District.'),
],
items: items,
);
}
I/flutter ( 6651): district=5
I/flutter ( 6651): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 6651): The following assertion was thrown building
I/flutter ( 6651): FormField-[LabeledGlobalKey<FormFieldState>#8e04e](dirty, dependencies:
I/flutter ( 6651): [_FormScope], state: FormFieldState#2e15b):
I/flutter ( 6651): 'package:flutter/src/material/dropdown.dart': Failed assertion: line 609 pos 15: 'items == null ||
I/flutter ( 6651): items.isEmpty || value == null || items.where((DropdownMenuItem item) => item.value ==
I/flutter ( 6651): value).length == 1': is not true.
I/flutter ( 6651):
The text was updated successfully, but these errors were encountered: