cpd_app_gruppe_finanzplaner/lib/transaction/transaction_dialog.dart

229 lines
7.9 KiB
Dart
Raw Permalink Normal View History

2023-06-15 00:55:02 +02:00
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:tests/transaction/transaction.dart';
2023-06-17 03:09:31 +02:00
import '../theme/theme_constants.dart';
2023-06-15 00:55:02 +02:00
class AddTransactionDialog extends StatefulWidget {
final Function addTransaction;
2023-06-17 03:09:31 +02:00
2023-06-15 00:55:02 +02:00
const AddTransactionDialog({super.key, required this.addTransaction});
@override
AddTransactionDialogState createState() => AddTransactionDialogState();
}
class AddTransactionDialogState extends State<AddTransactionDialog> {
final _formKey = GlobalKey<FormState>();
final _titleController = TextEditingController();
final _amountController = TextEditingController();
bool _isExpense = true;
@override
void dispose() {
_titleController.dispose();
_amountController.dispose();
super.dispose();
}
void _submitForm() {
if (_formKey.currentState!.validate()) {
String title = _titleController.text.trim();
double amount = double.parse(_amountController.text.trim());
Transaction transaction = Transaction(
title: title,
amount: amount,
isExpense: _isExpense,
date: DateTime.now(),
);
widget.addTransaction(transaction);
Navigator.of(context).pop();
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
title: Text(
'addtrans'.tr(),
style: const TextStyle(
fontSize: 20,
),
),
content: Form(
2023-06-17 03:09:31 +02:00
key: _formKey, //
2023-06-15 00:55:02 +02:00
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Neumorphic(
style: NeumorphicStyle(
depth: -5,
intensity: 0.8,
2023-06-17 03:09:31 +02:00
shadowLightColor:
Theme.of(context).brightness == Brightness.light
? const NeumorphicStyle().shadowLightColor
: Theme.of(context).shadowColor,
shadowDarkColor:
Theme.of(context).brightness == Brightness.dark
? const NeumorphicStyle().shadowDarkColor
: grey400,
color: Theme.of(context).brightness == Brightness.light
? grey200
: grey800,
2023-06-15 00:55:02 +02:00
boxShape: NeumorphicBoxShape.roundRect(
BorderRadius.circular(12),
),
),
child: TextFormField(
controller: _titleController,
decoration: const InputDecoration(
labelText: 'Title',
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
vertical: 12,
horizontal: 16,
),
),
validator: (value) {
if (value!.isEmpty) {
return 'entertitle'.tr();
}
return null;
},
),
),
const SizedBox(height: 16),
Neumorphic(
style: NeumorphicStyle(
depth: -5,
intensity: 0.8,
2023-06-17 03:09:31 +02:00
shadowLightColor:
Theme.of(context).brightness == Brightness.light
? const NeumorphicStyle().shadowLightColor
: Theme.of(context).shadowColor,
shadowDarkColor:
Theme.of(context).brightness == Brightness.dark
? const NeumorphicStyle().shadowDarkColor
: grey400,
color: Theme.of(context).brightness == Brightness.light
? grey200
: grey800,
2023-06-15 00:55:02 +02:00
boxShape: NeumorphicBoxShape.roundRect(
BorderRadius.circular(12),
),
),
child: TextFormField(
controller: _amountController,
decoration: InputDecoration(
labelText: 'amount'.tr(),
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 16,
),
),
keyboardType: TextInputType.number,
validator: (value) {
if (value!.isEmpty) {
return 'enteramount'.tr();
}
if (double.tryParse(value) == null) {
return 'entervalidnumber'.tr();
}
return null;
},
),
),
const SizedBox(height: 16),
Row(
children: [
NeumorphicCheckbox(
style: NeumorphicCheckboxStyle(
selectedColor: Colors.lightGreen,
2023-06-17 03:09:31 +02:00
disabledColor:
Theme.of(context).brightness == Brightness.light
? grey200
: grey800,
2023-06-15 00:55:02 +02:00
selectedDepth: -10,
2023-06-18 03:00:17 +02:00
unselectedDepth: 6),
2023-06-15 00:55:02 +02:00
value: _isExpense,
onChanged: (value) {
setState(() {
_isExpense = value!;
});
},
),
2023-06-18 03:00:17 +02:00
const SizedBox(width: 9),
2023-06-15 00:55:02 +02:00
Text(
'expense'.tr(),
),
],
),
],
)),
actions: [
NeumorphicButton(
onPressed: () {
Navigator.of(context).pop();
},
style: NeumorphicStyle(
shape: NeumorphicShape.concave,
intensity: 0.8,
depth: 9,
boxShape: NeumorphicBoxShape.roundRect(
BorderRadius.circular(12),
),
2023-06-17 03:09:31 +02:00
shadowLightColor: Theme.of(context).brightness == Brightness.light
? const NeumorphicStyle().shadowLightColor
: Theme.of(context).shadowColor,
shadowDarkColor: Theme.of(context).brightness == Brightness.dark
? const NeumorphicStyle().shadowDarkColor
: grey400,
color: Theme.of(context).brightness == Brightness.light
? grey200
: grey800,
2023-06-15 00:55:02 +02:00
),
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Text(
'cancel'.tr(),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
NeumorphicButton(
onPressed: _submitForm,
style: NeumorphicStyle(
shape: NeumorphicShape.concave,
intensity: 0.8,
depth: 9,
boxShape: NeumorphicBoxShape.roundRect(
BorderRadius.circular(12),
),
2023-06-17 03:09:31 +02:00
shadowLightColor: Theme.of(context).brightness == Brightness.light
? const NeumorphicStyle().shadowLightColor
: Theme.of(context).shadowColor,
shadowDarkColor: Theme.of(context).brightness == Brightness.dark
? const NeumorphicStyle().shadowDarkColor
: grey400,
color: Theme.of(context).brightness == Brightness.light
? grey200
: grey800,
2023-06-15 00:55:02 +02:00
),
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Text(
'add'.tr(),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
],
);
}
}