0

I have issue with the below code written in Flutter. I am trying to implement a search bar where I will show the results based on the match query string. The variable isStorage is set to false in the beginning. However, when I try to update its value inside _getALlPosts(), it is not getting updated.

class _HomeState extends State<Home> {
 final SearchBarController<Post> _searchBarController = SearchBarController();
 bool isReplay = false;
 bool isStorage = false;

 Future<List<Post>> _getALlPosts(String text) async {
await Future.delayed(Duration(seconds: text.length == 4 ? 2 : 1));

List<Post> posts = [];
var random = new Random();

if (text.contains("pha")) {
  isStorage = true;
}
}
}

2 Answers 2

1

You need to use setState to update the value:

if (text.contains("pha")) {
     setState(() {
      isStorage = true;
    });
}
Sign up to request clarification or add additional context in comments.

Comments

1

I believe you're missing a setState wrapping the isStorage = true;

setState(() {
  isStorage = true;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.