salim-lachdhaf / dropdown_search

Simple and robust Dropdown with item search feature, making it possible to use an offline item list or filtering URL for easy customization.
MIT License
346 stars 334 forks source link

Add a way to refresh data especially when error. #682

Open Trung15010802 opened 1 month ago

Trung15010802 commented 1 month ago

Is your feature request related to a problem? Please describe. Add a feature to refresh data when error.

Describe the solution you'd like Using search box isn't a good way

salim-lachdhaf commented 1 month ago

What do you suggest ?

vasilich6107 commented 1 month ago

Hey @salim-lachdhaf There is probably a nice pattern to follow, check the gif on main page of https://pub.dev/packages/infinite_scroll_pagination

When there is an error during fetching the data the list is being replaced by the error message widget. There is also a retry callback being passed to error widget so user could build the error widget with refresh button.

You can spot one of those examples on gif (at the very bottom)

image
vasilich6107 commented 1 month ago

In addition to error refresh - the pull to refresh mechanism for the list view would be a nice addition

Trung15010802 commented 1 month ago

What do you suggest ?

I want a way to trigger items function again in errorBuilder

This is my temporary solution: errorBuilder: (context, searchEntry, exception) {

          return Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Text(
                textAlign: TextAlign.center,
                LocKeys.someErrorOccur.tr(context: context),
                style: TextStyle(color: appColors.webTextColor),
              ),
              if (widget.onRefreshError != null)
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: CommonButtonWidget(
                    callBack: () async {
                      _searchController.text = '###';
                      widget.onRefreshError!().whenComplete(
                        () => _searchController.text = originalText,
                      );
                    },
                    label: LocKeys.refresh.tr(context: context),
                    icon: const Icon(
                      Icons.refresh,
                    ),
                  ),
                ),
            ],
          );
        }