filtering works!
This commit is contained in:
@@ -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,19 +221,21 @@ 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),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -246,23 +251,83 @@ class ListPage extends StatelessWidget {
|
|||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return SizedBox(
|
return Padding(
|
||||||
height: 300,
|
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||||
child: ListView(
|
child: Column(
|
||||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
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: () {
|
||||||
ListTile(
|
_showFilterOptionsBottomSheet(context, provider);
|
||||||
title: Text(Strings.exportSelectedQuotes),
|
},
|
||||||
trailing: Icon(Icons.import_export),
|
),
|
||||||
),
|
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 {
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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";
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user