added prototype of the filter bar + all quotes count
This commit is contained in:
+131
-54
@@ -17,11 +17,11 @@ class ListPage extends StatelessWidget {
|
||||
onRefresh: () async {
|
||||
await provider.readQuotes();
|
||||
},
|
||||
child: _bodyBuilder(provider),
|
||||
child: _bodyBuilder(context, provider),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _bodyBuilder(QuoteProvider provider) {
|
||||
Widget _bodyBuilder(BuildContext context, QuoteProvider provider) {
|
||||
if (provider.loading) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
@@ -30,61 +30,79 @@ class ListPage extends StatelessWidget {
|
||||
return Center(child: Text(provider.error!));
|
||||
}
|
||||
|
||||
final quoteCount = provider.quotes.length;
|
||||
|
||||
return
|
||||
ListView.builder(
|
||||
padding: EdgeInsets.all(Constants.edgeInset),
|
||||
itemCount: provider.quotes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final quote = provider.quotes[index];
|
||||
|
||||
return
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.only(
|
||||
bottom: Constants.edgeInset,
|
||||
left: Constants.edgeInset,
|
||||
right: Constants.edgeInset,
|
||||
),
|
||||
title: Text(quote.body),
|
||||
subtitle: Text("– ${quote.author}"),
|
||||
trailing: PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
|
||||
onSelected: (value) {
|
||||
if (value == 'update') {
|
||||
// open a dialog window that allows for mods
|
||||
_showUpdateDialog(context, provider, quote);
|
||||
} else if (value == 'delete') {
|
||||
// open a confirmation dialog window for deletion
|
||||
_showDeleteDialog(context, provider, quote);
|
||||
}
|
||||
},
|
||||
|
||||
itemBuilder: (context) => [
|
||||
const PopupMenuItem(
|
||||
value: 'update',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.edit),
|
||||
SizedBox(width: 10),
|
||||
Text(Strings.updateQuote),
|
||||
],
|
||||
Column(
|
||||
children: [
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||
child: Text(
|
||||
'${Strings.allQuotesCount} – $quoteCount',
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
),
|
||||
filterBar(context, provider),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.all(Constants.edgeInset),
|
||||
itemCount: provider.quotes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final quote = provider.quotes[index];
|
||||
|
||||
return
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.only(
|
||||
bottom: Constants.edgeInset,
|
||||
left: Constants.edgeInset,
|
||||
right: Constants.edgeInset,
|
||||
),
|
||||
),
|
||||
|
||||
const PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete),
|
||||
SizedBox(width: 10),
|
||||
Text(Strings.deleteQuote),
|
||||
title: Text(quote.body),
|
||||
subtitle: Text("– ${quote.author}"),
|
||||
trailing: PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
|
||||
onSelected: (value) {
|
||||
if (value == 'update') {
|
||||
// open a dialog window that allows for mods
|
||||
_showUpdateDialog(context, provider, quote);
|
||||
} else if (value == 'delete') {
|
||||
// open a confirmation dialog window for deletion
|
||||
_showDeleteDialog(context, provider, quote);
|
||||
}
|
||||
},
|
||||
|
||||
itemBuilder: (context) => [
|
||||
const PopupMenuItem(
|
||||
value: 'update',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.edit),
|
||||
SizedBox(width: 10),
|
||||
Text(Strings.updateQuote),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete),
|
||||
SizedBox(width: 10),
|
||||
Text(Strings.deleteQuote),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -191,4 +209,63 @@ class ListPage extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget filterBar(BuildContext context, QuoteProvider provider) {
|
||||
int filterBy = 0; // 0 = by author, 1 = by quote
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: provider.filterController,
|
||||
decoration: InputDecoration(
|
||||
label: Text(Strings.filterQuery),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.cancel),
|
||||
onPressed: provider.clearFilterController
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search),
|
||||
onPressed: () {
|
||||
// TODO: filtering
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.more_horiz),
|
||||
onPressed: () {
|
||||
_showOptionsBottomSheet(context, provider);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showOptionsBottomSheet(BuildContext context, QuoteProvider provider) {
|
||||
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),
|
||||
),
|
||||
],
|
||||
)
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user