cetorres / multiselect_formfield

A Flutter package that provides a multi select form field using alert dialog to select multiple items with checkboxes and showing as chips.
BSD 3-Clause "New" or "Revised" License
71 stars 58 forks source link

No items can be selected if a text has been written into a TextFormField immediately before (focus still active) #50

Open teilzeitgeist opened 2 years ago

teilzeitgeist commented 2 years ago

The two widgets:

CustomScrollView(shrinkWrap: true, slivers: [
                  SliverToBoxAdapter(
                      child: Column(children: [
                    Container(
                      height: 1,
                      color: kColorUltraLightGrey,
                    ),
                    SizedBox(height: 28),
                    EditTextField(
                      label: Utils.t(context, 'interim_note_form.note'),
                      padding: EdgeInsets.symmetric(horizontal: 16),
                      isExpandable: true,
                      controller: _messageController,
                    ),
                    FileUpload(
                      label: Utils.t(context, 'interim_note_form.action_add_photo'),
                      fileType: FileType.image,
                      didSelectFiles: (files) => _files = files,
                      files: _files,
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
                      child: Stack(
                        key: multiSelectFormFieldKey,
                        children: [
                          MultiSelectFormField(
                            title: Text(Utils.t(context, 'interim_note_form.concerned_modules'), style: TextStyle(fontSize: 11, color: kColorLabel)),
                            fillColor: kColorBackgroundFormField,
                            dataSource: _moduleOptions ?? [],
                            initialValue: _selectedModuleIds,
                            textField: 'display',
                            valueField: 'value',
                            hintWidget: Padding(
                              padding: const EdgeInsets.only(bottom: 4.0),
                              child: Text(Utils.t(context, 'form.choose'), style: kTextStyleBody.copyWith(color: kColorLabel)),
                            ),
                            chipBackGroundColor: kColorWhite,
                            chipLabelStyle: TextStyle(fontSize: 13, color: kColorLabel, fontWeight: FontWeight.w600),
                            dialogShapeBorder: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))),
                            dialogTextStyle: kTextStyleAlertContent,
                            cancelButtonLabel: Utils.t(context, 'form.cancel').toUpperCase(),
                            onSaved: (value) {
                              if (value == null) return;
                              setState(() {
                                _selectedModuleIds = value;
                              });
                            },
                          ),
                          Positioned.fill(
                              right: 12,
                              bottom: _selectedModuleIds.length > 0 ? 24 : 10,
                              child: Container(
                                alignment: Alignment.bottomRight,
                                child: IgnorePointer(
                                  child: Container(
                                    color: kColorBackgroundFormField,
                                    height: double.infinity,
                                    width: 25,
                                    alignment: Alignment.bottomCenter,
                                    child: Icon(
                                      Icons.arrow_drop_down_sharp,
                                      size: 25,
                                    ),
                                  ),
                                ),
                              ))
                        ],
                      ),
                    ),
                    SizedBox(height: 132),
                  ]))
                ])

The error message is

E/flutter (13216): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: setState() called after dispose(): FormFieldState<dynamic>#03479(lifecycle state: defunct, not mounted)
E/flutter (13216): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter (13216): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter (13216): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
E/flutter (13216): #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1073:9)
E/flutter (13216): #1      State.setState (package:flutter/src/widgets/framework.dart:1108:6)
E/flutter (13216): #2      FormFieldState.didChange (package:flutter/src/widgets/form.dart:409:5)
E/flutter (13216): #3      new MultiSelectFormField.<anonymous closure>.<anonymous closure> (package:multiselect_formfield/multiselect_formfield.dart:120:25)
E/flutter (13216): <asynchronous suspension>
E/flutter (13216): 

Have anyone the same problem or can help me please?