filtering works!
This commit is contained in:
@@ -119,6 +119,9 @@ class ListPage extends StatelessWidget {
|
||||
children: [
|
||||
TextField(
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
label: Text(Strings.quote)
|
||||
),
|
||||
controller: bodyController,
|
||||
),
|
||||
TextField(
|
||||
@@ -218,19 +221,21 @@ class ListPage extends StatelessWidget {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: provider.filterController,
|
||||
onChanged: (_) => provider.filterQuotes(),
|
||||
decoration: InputDecoration(
|
||||
label: Text(Strings.filterQuery),
|
||||
label: Text(
|
||||
'${Strings.filterQuery} – ${Strings.byAttribute} ${(provider.filterBy == 0) ? Strings.author : Strings.quote}'
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.cancel),
|
||||
onPressed: provider.clearFilterController
|
||||
)
|
||||
onPressed: () {
|
||||
provider.clearFilterController();
|
||||
provider.filterQuotes();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search),
|
||||
onPressed: provider.filterQuotes,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.more_horiz),
|
||||
onPressed: () {
|
||||
@@ -246,23 +251,83 @@ class ListPage extends StatelessWidget {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(Strings.filterBy),
|
||||
trailing: Icon(Icons.filter_alt),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(Strings.exportSelectedQuotes),
|
||||
trailing: Icon(Icons.import_export),
|
||||
),
|
||||
],
|
||||
)
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(Strings.filterBy),
|
||||
trailing: Icon(Icons.filter_alt),
|
||||
onTap: () {
|
||||
_showFilterOptionsBottomSheet(context, provider);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(Strings.exportSelectedQuotes),
|
||||
trailing: Icon(Icons.import_export),
|
||||
onTap: () {
|
||||
// TODO: trigger an os dialog FileSave
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showFilterOptionsBottomSheet(
|
||||
BuildContext context,
|
||||
QuoteProvider provider,
|
||||
) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text(Strings.author),
|
||||
leading: Radio<int>(
|
||||
value: 0,
|
||||
groupValue: provider.filterBy,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
provider.setFilterBy(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
onTap: () {
|
||||
provider.setFilterBy(0);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
|
||||
ListTile(
|
||||
title: const Text(Strings.quote),
|
||||
leading: Radio<int>(
|
||||
value: 1,
|
||||
groupValue: provider.filterBy,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
provider.setFilterBy(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
onTap: () {
|
||||
provider.setFilterBy(1);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import 'package:frontend/repository/quote_repository.dart';
|
||||
|
||||
class QuoteProvider extends ChangeNotifier {
|
||||
List<Quote> _quotes = [];
|
||||
List<Quote> _filteredQuotes = [];
|
||||
Set<String> _authors = {};
|
||||
bool _loading = false;
|
||||
String? _error;
|
||||
@@ -40,6 +39,10 @@ class QuoteProvider extends ChangeNotifier {
|
||||
filterController.text = '';
|
||||
}
|
||||
|
||||
void filterQuotes() {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
QuoteProvider() {
|
||||
readQuotes(); // auto-load on creation
|
||||
}
|
||||
@@ -51,7 +54,8 @@ class QuoteProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void filterQuotes() {
|
||||
void setFilterBy(int value) {
|
||||
filterBy = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -62,7 +66,6 @@ class QuoteProvider extends ChangeNotifier {
|
||||
|
||||
try {
|
||||
_quotes = await repo.readQuotes();
|
||||
_filteredQuotes = _quotes;
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
}
|
||||
|
||||
@@ -24,4 +24,5 @@ class Strings {
|
||||
static const String allQuotesCount = "Celkový počet hlášek";
|
||||
static const String filterBy = "Filtrovat podle";
|
||||
static const String exportSelectedQuotes = "Exportovat vybrané hlášky";
|
||||
static const String byAttribute = "podle příznaku";
|
||||
}
|
||||
Reference in New Issue
Block a user