119 lines
3.7 KiB
Dart
119 lines
3.7 KiB
Dart
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';
|
|
|
|
class AddPage extends StatelessWidget {
|
|
const AddPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bodyController = TextEditingController(text: '');
|
|
final authorController = TextEditingController(text: '');
|
|
final provider = Provider.of<QuoteProvider>(context);
|
|
return Card(
|
|
margin: const EdgeInsets.all(Constants.edgeInset),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(Constants.edgeInset),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
Strings.createQuote,
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
TextField(
|
|
autofocus: true,
|
|
controller: bodyController,
|
|
decoration: const InputDecoration(
|
|
labelText: Strings.quote,
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
TextField(
|
|
controller: authorController,
|
|
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);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () {
|
|
bodyController.clear();
|
|
authorController.clear();
|
|
},
|
|
child: const Text(Strings.cancel),
|
|
),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
final quote = Quote(
|
|
id: 0,
|
|
body: bodyController.text,
|
|
author: authorController.text,
|
|
);
|
|
|
|
provider.createQuote(quote);
|
|
|
|
bodyController.clear();
|
|
authorController.clear();
|
|
},
|
|
child: const Text(Strings.save),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |