fixed issue #5
This commit is contained in:
@@ -64,7 +64,7 @@ class QuoteProvider extends ChangeNotifier {
|
|||||||
filterController.text = '';
|
filterController.text = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
Quote randomQuote = Quote(id: 0, author: "dummy", body: "text");
|
late Quote randomQuote;
|
||||||
bool randomQuoteDeterminator = true;
|
bool randomQuoteDeterminator = true;
|
||||||
String get randomQuoteText {
|
String get randomQuoteText {
|
||||||
if (randomQuoteDeterminator) {
|
if (randomQuoteDeterminator) {
|
||||||
@@ -80,6 +80,7 @@ class QuoteProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nextRandomQuote() {
|
void nextRandomQuote() {
|
||||||
|
if (filteredQuotes.isEmpty) return;
|
||||||
final random = Random();
|
final random = Random();
|
||||||
randomQuote = filteredQuotes[random.nextInt(filteredQuotes.length)];
|
randomQuote = filteredQuotes[random.nextInt(filteredQuotes.length)];
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -107,17 +108,20 @@ class QuoteProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> readQuotes() async {
|
Future<void> readQuotes() async {
|
||||||
_loading = true;
|
_loading = true;
|
||||||
_error = null;
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_quotes = await repo.readQuotes();
|
_quotes = await repo.readQuotes();
|
||||||
|
populateAuthors();
|
||||||
|
|
||||||
|
if (_quotes.isNotEmpty) {
|
||||||
|
nextRandomQuote();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_error = e.toString();
|
_error = e.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
populateAuthors();
|
|
||||||
|
|
||||||
_loading = false;
|
_loading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user