Reputation: 1236
I have provider that I build by learning from course, and there is set
variables if I remove it nothing change and everything works fine but I'm afraid in future something will go error.
Here is my code:
class SimilarMovieProvider with ChangeNotifier {
List<SimilarMovieModel> _similarMovie = [];
bool _isLoading = true;
List<SimilarMovieModel> get similarMovie => _similarMovie;
bool get isLoading => _isLoading;
set similarMovie(List<SimilarMovieModel> _similarMovie) {
_similarMovie = similarMovie;
notifyListeners();
}
set isLoading(bool _isLoading) {
_isLoading = isLoading;
notifyListeners();
}
Future getSimilarMovie(movieId) async {
_isLoading = true;
try {
List<SimilarMovieModel> similarMovie =
await Http().getSimilarMovie(movieId);
_similarMovie = similarMovie;
_isLoading = false;
notifyListeners();
} catch (error) {
_isLoading = false;
notifyListeners();
print(error);
}
}
}
Upvotes: 0
Views: 33
Reputation: 66
As far as I am concerned it doesn't change anything. You just switch from using a setter to using a method to update your instance.
Upvotes: 2