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

adding as favorite conditionally #6

Open
Salman3sh opened this issue Jan 11, 2023 · 2 comments
Open

adding as favorite conditionally #6

Salman3sh opened this issue Jan 11, 2023 · 2 comments

Comments

@Salman3sh
Copy link

I have a listview and for each row, I added the option to add it as a favorite. I also have a condition in the backend that if the number of favorites is more than 10, the responsecode equals to 2 and shows an error in the flutter and does not add it to the favorite.

Everything works perfectly. The only problem that I have is that in conditions with more than 10 favorites, however, it does not add it to the list (when I refresh the page, it hsows as unmarked), but when I click, it marks as favorite. How could I unmark it as favorite, for example, when user closes the showDialog?

Any other approach is also appreciated like simulating the onpressed action to undo the action of favoriting.

Thank you in advance.

StarButton(
  isStarred: UserFavorite
      .Users!
  valueChanged: (_isStarred) {
    if (_isStarred == true)
      setState(() async {
        var resp =
            await add(
                widget.oauth,
                widget.gatewayId,);
        if (resp.responseCode ==
            2) {
          await showDialog(
            context: context,
            builder:
                (alertDialogContext) {
              return AlertDialog(
                title: Text(
                    'Limit Reached'),
                content: Text(
                    'You are allowed to add up to 10 sensors as your favorite.'),
                actions: [
                  TextButton(
                    child: Text(
                        'Ok'),
                    onPressed:
                        () {
                      Navigator.pop(
                          alertDialogContext);
                    },
                  ),
                ],
              );
            },
          );
        }
      });
    else
      setState(() {
        delete(
            widget.oauth,
            widget.Id,
       );
      });
  },
)

favorite_problem

@vishalkevin11
Copy link
Contributor

Hi @Salman3sh ,

I suspect the issue is here
isStarred: UserFavorite.Users!

Are you sure the value is right, it should be false when you refresh the page.

@Salman3sh
Copy link
Author

Hi @Salman3sh ,

I suspect the issue is here isStarred: UserFavorite.Users!

Are you sure the value is right, it should be false when you refresh the page.

Thanks for the reply.

this part has no issue. I am using a listview and for each row, I check if it is already false or true and it shows as it is.

The code works perfectly but my problem is that I want to have a limit on the number of favorited rows. Even the condition works perfectly(does not allow more than 10 favorite) but when users click on the favorite button, it first makes it as favorite(color is changed and it is my problem) and then gives the warning. However, when I refresh the page, it is not favorited.

Do you have any suggestion that it does not show as the favorite and revert to not favorite after user read the alertdialog?

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

No branches or pull requests

2 participants