Skip to content
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

customize the "Error - retry" #56

Closed
rhernandez-itemsoft opened this issue Dec 9, 2021 · 3 comments
Closed

customize the "Error - retry" #56

rhernandez-itemsoft opened this issue Dec 9, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@rhernandez-itemsoft
Copy link

Can I customize the "Error - retry" button?

@lcuis
Copy link
Owner

lcuis commented Dec 9, 2021

Hello @rhernandez-itemsoft ,

Thanks for your request. At the moment, there is no easy way to customize the “Error - retry” button and this is missing. I will mark this issue as an enhancement and work on it as soon as I can.

@lcuis lcuis self-assigned this Dec 9, 2021
@lcuis lcuis added the enhancement New feature or request label Dec 9, 2021
lcuis added a commit that referenced this issue Dec 9, 2021
Customize error - retry button through new parameter futureSearchRetryButton. Thanks @rhernandez-itemsoft #56
lcuis added a commit that referenced this issue Dec 9, 2021
Customize error - retry button through new parameter futureSearchRetryButton. Thanks @rhernandez-itemsoft #56
lcuis added a commit that referenced this issue Dec 10, 2021
Customize error - retry button through new parameter futureSearchRetryButton. Thanks @rhernandez-itemsoft #56
lcuis added a commit that referenced this issue Dec 10, 2021
Customize error - retry button through new parameter futureSearchRetryButton. Thanks @rhernandez-itemsoft #56
lcuis added a commit that referenced this issue Dec 10, 2021
Customize error - retry button through new parameter futureSearchRetryButton. Thanks @rhernandez-itemsoft #56
@lcuis
Copy link
Owner

lcuis commented Dec 10, 2021

Hello @rhernandez-itemsoft ,

The latest release 1.0.15 available on pub.dev should address your request with the following example:
https://github.com/lcuis/search_choices#Single-dialog-future-custom-error-button

Single dialog future custom error button

SearchChoices.single(
        value: selectedValueSingleDialogFuture,
        hint: kIsWeb ? "Example not for web" : "Select one capital",
        searchHint: "Search capitals",
        onChanged: kIsWeb
            ? null
            : (value) {
          setState(() {
            selectedValueSingleDialogFuture = value;
          });
        },
        isExpanded: true,
        selectedValueWidgetFn: (item) {
          return (Center(
              child: Card(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(4),
                    side: BorderSide(
                      color: Colors.grey,
                      width: 1,
                    ),
                  ),
                  margin: EdgeInsets.all(1),
                  child: Padding(
                    padding: const EdgeInsets.all(6),
                    child: Text(item["capital"]),
                  ))));
        },
        futureSearchFn: (String? keyword, String? orderBy, bool? orderAsc,
            List<Tuple2<String, String>>? filters, int? pageNb) async {
          String filtersString = "";
          int i = 1;
          filters?.forEach((element) {
            // This example doesn't have any futureSearchFilterOptions parameter, thus, this loop will never run anything.
            filtersString += "&filter" +
                i.toString() +
                "=" +
                element.item1 +
                "," +
                element.item2;
            i++;
          });
          Response response = await get(Uri.parse(
              "https://FAULTYsearchchoices.jod.li/exampleList.php?page=${pageNb ?? 1},10${orderBy == null ? "" : "&order=" + orderBy + "," + (orderAsc ?? true ? "asc" : "desc")}${(keyword == null || keyword.isEmpty) ? "" : "&filter=capital,cs," + keyword}$filtersString"))
              .timeout(Duration(
            seconds: 10,
          ));
          if (response.statusCode != 200) {
            throw Exception("failed to get data from internet");
          }
          dynamic data = jsonDecode(response.body);
          int nbResults = data["results"];
          List<DropdownMenuItem> results = (data["records"] as List<dynamic>)
              .map<DropdownMenuItem>((item) => DropdownMenuItem(
            value: item,
            child: Card(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(4),
                side: BorderSide(
                  color: Colors.blue,
                  width: 1,
                ),
              ),
              margin: EdgeInsets.all(10),
              child: Padding(
                padding: const EdgeInsets.all(6),
                child: Text(
                    "${item["capital"]} - ${item["country"]} - ${item["continent"]} - pop.: ${item["population"]}"),
              ),
            ),
          ))
              .toList();
          return (Tuple2<List<DropdownMenuItem>, int>(results, nbResults));
        },
        futureSearchRetryButton: (Function onPressed) => Column(children: [
          SizedBox(height: 15),
          Center(
            child: ElevatedButton.icon(
                onPressed: (){onPressed();},
                icon: Icon(Icons.repeat),
                label: Text("Intentional error - retry")),
          )
        ]),
      )

I hope this will work for you.

@rhernandez-itemsoft
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants