Skip to content

Commit

Permalink
Fix update and add recurring transaction + style
Browse files Browse the repository at this point in the history
  • Loading branch information
K-w-e committed May 6, 2024
1 parent 7bbf302 commit ce0294d
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 137 deletions.
2 changes: 1 addition & 1 deletion lib/model/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class TransactionMethods extends SossoldiDatabase {
Future<List<Transaction>> getRecurrenceTransactionsById({int? id}) async {
final db = await database;

final result = await db.rawQuery('SELECT * FROM "$transactionTable" as t WHERE t.${TransactionFields.idRecurringTransaction} = $id');
final result = await db.rawQuery('SELECT * FROM "$transactionTable" as t WHERE t.${TransactionFields.idRecurringTransaction} = $id ORDER BY ${TransactionFields.date} DESC');

return result.map((json) => Transaction.fromJson(json)).toList();
}
Expand Down
37 changes: 2 additions & 35 deletions lib/pages/add_page/widgets/amount_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../../../constants/style.dart";
import '../../../model/transaction.dart';
import '../../../providers/currency_provider.dart';
import '../../../providers/transactions_provider.dart';
import '../../../pages/add_page/widgets/amount_widget.dart';
import 'account_selector.dart';
import 'type_tab.dart';

Expand Down Expand Up @@ -269,41 +270,7 @@ class _AmountSectionState extends ConsumerState<AmountSection> with Functions {
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
child: TextField(
controller: widget.amountController,
decoration: InputDecoration(
hintText: "0",
border: InputBorder.none,
prefixText: ' ', // set to center the amount
suffixText: currencyState.selectedCurrency.symbol,
suffixStyle: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: typeToColor(selectedType)),
),
keyboardType: const TextInputType.numberWithOptions(decimal: true, signed: true),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'\d*\.?\d{0,2}')),
],
// inputFormatters: [DecimalTextInputFormatter(decimalDigits: 2)],
autofocus: false,
textAlign: TextAlign.center,
cursorColor: grey1,
style: TextStyle(
color: typeToColor(selectedType),
fontSize: 58,
fontWeight: FontWeight.bold,
),
onTapOutside: (_){
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
),
),
AmountWidget(widget.amountController),
],
),
);
Expand Down
64 changes: 64 additions & 0 deletions lib/pages/add_page/widgets/amount_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import "package:flutter_riverpod/flutter_riverpod.dart";

import '../../../constants/functions.dart';
import "../../../constants/style.dart";
import '../../../providers/currency_provider.dart';
import '../../../providers/transactions_provider.dart';

class AmountWidget extends ConsumerStatefulWidget {
const AmountWidget(
this.amountController, {
super.key,
});

final TextEditingController amountController;

@override
ConsumerState<AmountWidget> createState() => _AmountWidgetState();
}

class _AmountWidgetState extends ConsumerState<AmountWidget> with Functions {
@override
Widget build(BuildContext context) {
final selectedType = ref.watch(transactionTypeProvider);
final currencyState = ref.watch(currencyStateNotifier);

return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
child: TextField(
controller: widget.amountController,
decoration: InputDecoration(
hintText: "0",
border: InputBorder.none,
prefixText: ' ',
suffixText: currencyState.selectedCurrency.symbol,
suffixStyle: Theme.of(context)
.textTheme
.headlineMedium!
.copyWith(color: typeToColor(selectedType)),
),
keyboardType:
const TextInputType.numberWithOptions(decimal: true, signed: true),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'\d*\.?\d{0,2}')),
],
autofocus: false,
textAlign: TextAlign.center,
cursorColor: grey1,
style: TextStyle(
color: typeToColor(selectedType),
fontSize: 58,
fontWeight: FontWeight.bold,
),
onTapOutside: (_) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
),
);
}
}
38 changes: 35 additions & 3 deletions lib/pages/add_page/widgets/recurrence_list_tile.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import "package:flutter_riverpod/flutter_riverpod.dart";

import '../../../constants/functions.dart';
import "../../../constants/style.dart";
import '../../../providers/transactions_provider.dart';
import '../../../model/transaction.dart';
import 'recurrence_selector.dart';

class RecurrenceListTile extends ConsumerWidget {
class RecurrenceListTile extends ConsumerWidget with Functions {
const RecurrenceListTile({
super.key,
});
Expand Down Expand Up @@ -98,7 +102,35 @@ class RecurrenceListTile extends ConsumerWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4)),
),
onPressed: () {},
onPressed: () async {
FocusManager.instance.primaryFocus?.unfocus();
if (Platform.isIOS) {
showCupertinoModalPopup(
context: context,
builder: (_) => Container(
height: 300,
color: white,
child: CupertinoDatePicker(
initialDateTime: ref.watch(endDateProvider),
minimumYear: 2015,
maximumYear: 2050,
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (date) => ref.read(endDateProvider.notifier).state = date,
),
),
);
} else if (Platform.isAndroid) {
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: ref.watch(endDateProvider),
firstDate: DateTime(2015),
lastDate: DateTime(2050),
);
if (pickedDate != null) {
ref.read(endDateProvider.notifier).state = pickedDate;
}
}
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -111,7 +143,7 @@ class RecurrenceListTile extends ConsumerWidget {
),
const Spacer(),
Text(
"Never",
dateToString(ref.read(endDateProvider.notifier).state),
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.secondary),
),
Expand Down
189 changes: 189 additions & 0 deletions lib/pages/planning_page/widget/edit_recurring_transaction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import 'dart:io' show Platform;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../constants/functions.dart';
import '../../../constants/style.dart';
import '../../../providers/transactions_provider.dart';
import '../../add_page/widgets/amount_widget.dart';
import '../../add_page/widgets/details_list_tile.dart';
import '../../add_page/widgets/label_list_tile.dart';
import '../../add_page/widgets/recurrence_list_tile.dart';

class EditRecurringTransaction extends ConsumerStatefulWidget {
const EditRecurringTransaction({super.key});

@override
ConsumerState<EditRecurringTransaction> createState() =>
_EditRecurringTransactionState();
}

class _EditRecurringTransactionState
extends ConsumerState<EditRecurringTransaction> with Functions {
final TextEditingController amountController = TextEditingController();
final TextEditingController noteController = TextEditingController();

@override
void initState() {
amountController.text = numToCurrency(ref.read(selectedRecurringTransactionUpdateProvider)?.amount);
noteController.text = ref.read(selectedRecurringTransactionUpdateProvider)?.note ?? '';

super.initState();
}

@override
Widget build(BuildContext context) {
final selectedRecurringTransaction = ref.watch(selectedRecurringTransactionUpdateProvider);

return Scaffold(
appBar: AppBar(
title: const Text("Editing recurring transaction"),
leadingWidth: 100,
leading: TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'Cancel',
style:
Theme.of(context).textTheme.titleMedium!.copyWith(color: blue5),
),
),
actions: [
selectedRecurringTransaction != null
? Container(
alignment: Alignment.centerRight,
child: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () async {
ref
.read(transactionsProvider.notifier)
.deleteRecurringTransaction(selectedRecurringTransaction.id!)
.whenComplete(() => Navigator.pop(context));
},
),
)
: const SizedBox(),
],
),
body: Stack(
children: [
SingleChildScrollView(
padding: const EdgeInsets.only(bottom: 72),
child: Column(
children: [
AmountWidget(amountController),
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 16, top: 32, bottom: 8),
child: Text(
"DETAILS",
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(color: Theme.of(context).colorScheme.primary),
),
),
Container(
color: Theme.of(context).colorScheme.surface,
child: Column(
children: [
LabelListTile(noteController),
const Divider(height: 1, color: grey1),
DetailsListTile(
title: "Date",
icon: Icons.calendar_month,
value: dateToString(ref.watch(dateProvider)),
callback: () async {
FocusManager.instance.primaryFocus?.unfocus();
if (Platform.isIOS) {
showCupertinoModalPopup(
context: context,
builder: (_) => Container(
height: 300,
color: white,
child: CupertinoDatePicker(
initialDateTime: ref.watch(dateProvider),
minimumYear: 2015,
maximumYear: 2050,
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (date) => ref
.read(dateProvider.notifier)
.state = date,
),
),
);
} else if (Platform.isAndroid) {
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: ref.watch(dateProvider),
firstDate: DateTime(2015),
lastDate: DateTime(2050),
);
if (pickedDate != null) {
ref.read(dateProvider.notifier).state =
pickedDate;
}
}
},
),
const RecurrenceListTile(),
],
),
),
],
),
),
Container(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
boxShadow: [
BoxShadow(
color: blue1.withOpacity(0.15),
blurRadius: 5.0,
offset: const Offset(0, -1.0),
)
],
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
child: Container(
height: 48,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondary,
boxShadow: [defaultShadow],
borderRadius: BorderRadius.circular(8),
),
child: TextButton(
onPressed: () => {
ref
.read(transactionsProvider.notifier)
.updateRecurringTransaction(
currencyToNum(amountController.text),
noteController.text)
.whenComplete(() => Navigator.of(context).pop())
},
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
),
child: Text(
"UPDATE TRANSACTION",
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Theme.of(context).colorScheme.background),
),
),
),
),
),
],
),
);
}
}
Loading

0 comments on commit ce0294d

Please sign in to comment.