filtering works!

This commit is contained in:
Odweta
2026-03-23 12:24:01 +01:00
parent ff655e2dcf
commit 1871dac2af
3 changed files with 94 additions and 25 deletions
+75 -10
View File
@@ -119,6 +119,9 @@ class ListPage extends StatelessWidget {
children: [ children: [
TextField( TextField(
autofocus: true, autofocus: true,
decoration: InputDecoration(
label: Text(Strings.quote)
),
controller: bodyController, controller: bodyController,
), ),
TextField( TextField(
@@ -218,18 +221,20 @@ class ListPage extends StatelessWidget {
Expanded( Expanded(
child: TextField( child: TextField(
controller: provider.filterController, controller: provider.filterController,
onChanged: (_) => provider.filterQuotes(),
decoration: InputDecoration( decoration: InputDecoration(
label: Text(Strings.filterQuery), label: Text(
'${Strings.filterQuery} ${Strings.byAttribute} ${(provider.filterBy == 0) ? Strings.author : Strings.quote}'
),
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon(Icons.cancel), icon: Icon(Icons.cancel),
onPressed: provider.clearFilterController onPressed: () {
) provider.clearFilterController();
provider.filterQuotes();
},
), ),
), ),
), ),
IconButton(
icon: Icon(Icons.search),
onPressed: provider.filterQuotes,
), ),
IconButton( IconButton(
icon: Icon(Icons.more_horiz), icon: Icon(Icons.more_horiz),
@@ -246,21 +251,81 @@ class ListPage extends StatelessWidget {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
builder: (context) { builder: (context) {
return SizedBox( return Padding(
height: 300,
child: ListView(
padding: const EdgeInsets.all(Constants.edgeInset), padding: const EdgeInsets.all(Constants.edgeInset),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [ children: [
ListTile( ListTile(
title: Text(Strings.filterBy), title: Text(Strings.filterBy),
trailing: Icon(Icons.filter_alt), trailing: Icon(Icons.filter_alt),
onTap: () {
_showFilterOptionsBottomSheet(context, provider);
},
), ),
ListTile( ListTile(
title: Text(Strings.exportSelectedQuotes), title: Text(Strings.exportSelectedQuotes),
trailing: Icon(Icons.import_export), 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);
},
),
],
),
); );
}, },
); );
+6 -3
View File
@@ -7,7 +7,6 @@ import 'package:frontend/repository/quote_repository.dart';
class QuoteProvider extends ChangeNotifier { class QuoteProvider extends ChangeNotifier {
List<Quote> _quotes = []; List<Quote> _quotes = [];
List<Quote> _filteredQuotes = [];
Set<String> _authors = {}; Set<String> _authors = {};
bool _loading = false; bool _loading = false;
String? _error; String? _error;
@@ -40,6 +39,10 @@ class QuoteProvider extends ChangeNotifier {
filterController.text = ''; filterController.text = '';
} }
void filterQuotes() {
notifyListeners();
}
QuoteProvider() { QuoteProvider() {
readQuotes(); // auto-load on creation readQuotes(); // auto-load on creation
} }
@@ -51,7 +54,8 @@ class QuoteProvider extends ChangeNotifier {
} }
} }
void filterQuotes() { void setFilterBy(int value) {
filterBy = value;
notifyListeners(); notifyListeners();
} }
@@ -62,7 +66,6 @@ class QuoteProvider extends ChangeNotifier {
try { try {
_quotes = await repo.readQuotes(); _quotes = await repo.readQuotes();
_filteredQuotes = _quotes;
} catch (e) { } catch (e) {
_error = e.toString(); _error = e.toString();
} }
+1
View File
@@ -24,4 +24,5 @@ class Strings {
static const String allQuotesCount = "Celkový počet hlášek"; static const String allQuotesCount = "Celkový počet hlášek";
static const String filterBy = "Filtrovat podle"; static const String filterBy = "Filtrovat podle";
static const String exportSelectedQuotes = "Exportovat vybrané hlášky"; static const String exportSelectedQuotes = "Exportovat vybrané hlášky";
static const String byAttribute = "podle příznaku";
} }