add author selection menu
This commit is contained in:
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:frontend/provider/quote_provider.dart';
|
||||
import 'package:frontend/model/quote.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:frontend/values/strings.dart';
|
||||
import 'package:frontend/values/constants.dart';
|
||||
|
||||
@@ -12,7 +14,7 @@ class AddPage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final bodyController = TextEditingController(text: '');
|
||||
final authorController = TextEditingController(text: '');
|
||||
final provider = QuoteProvider();
|
||||
final provider = Provider.of<QuoteProvider>(context);
|
||||
return Card(
|
||||
margin: const EdgeInsets.all(Constants.edgeInset),
|
||||
child: Padding(
|
||||
@@ -40,11 +42,40 @@ class AddPage extends StatelessWidget {
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
TextField(
|
||||
controller: authorController,
|
||||
decoration: const InputDecoration(
|
||||
decoration: InputDecoration(
|
||||
labelText: Strings.author,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.arrow_drop_down),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
var authors = provider.authors.toList()..sort();
|
||||
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||
itemCount: authors.length,
|
||||
itemBuilder: (context, index) {
|
||||
final author = authors[index];
|
||||
|
||||
return ListTile(
|
||||
title: Text(author),
|
||||
onTap: () {
|
||||
authorController.text = author;
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:frontend/provider/quote_provider.dart';
|
||||
import 'package:frontend/model/quote.dart';
|
||||
import 'package:frontend/strings.dart';
|
||||
import 'package:frontend/values/strings.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:frontend/values/constants.dart';
|
||||
|
||||
class ListPage extends StatelessWidget {
|
||||
const ListPage({super.key});
|
||||
|
||||
@@ -30,12 +32,18 @@ class ListPage extends StatelessWidget {
|
||||
|
||||
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>(
|
||||
@@ -97,6 +105,39 @@ class ListPage extends StatelessWidget {
|
||||
),
|
||||
TextField(
|
||||
controller: authorController,
|
||||
decoration: InputDecoration(
|
||||
label: Text(Strings.author),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.arrow_drop_down),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
var authors = provider.authors.toList()..sort();
|
||||
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||
itemCount: authors.length,
|
||||
itemBuilder: (context, index) {
|
||||
final author = authors[index];
|
||||
|
||||
return ListTile(
|
||||
title: Text(author),
|
||||
onTap: () {
|
||||
authorController.text = author;
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user