Skip to content

Commit

Permalink
[Mobile] トランザクション詳細遷移ロジック見直し #347
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamenod committed Jul 23, 2023
1 parent 91090d3 commit 9c0d178
Show file tree
Hide file tree
Showing 69 changed files with 1,344 additions and 2,738 deletions.
7 changes: 7 additions & 0 deletions mobile/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ rm coverage/source_lcov.info
# flutter pub global run dart_dot_reporter machine.log --show-message
'''

[tasks.test-logic]
script = '''
fvm flutter test --exclude-tags golden --coverage --coverage-path="coverage/source_lcov.info"
./node_modules/.bin/lcov-result-merger ./coverage/source_lcov.info ./coverage/lcov.info
rm coverage/source_lcov.info
'''

[tasks.ci-test]
script = '''
fvm flutter test
Expand Down
6 changes: 3 additions & 3 deletions mobile/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:suito/src/localizations/japanese_cupertino_localizations.dart';
import 'package:suito/src/routing/app_router.dart';
import 'package:suito/src/utils/version_check.dart';

class MyApp extends ConsumerWidget {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

MyApp({super.key});
class MyApp extends ConsumerWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down
2 changes: 1 addition & 1 deletion mobile/lib/src/app_bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AppBootstrap {
return TranslationProvider(
child: UncontrolledProviderScope(
container: container,
child: MyApp(),
child: const MyApp(),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:suito/i18n/translations.g.dart';

import 'expense_schedule_detail_view.dart';

class ExpenseScheduleDetailScreen extends ConsumerWidget {
const ExpenseScheduleDetailScreen({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: AppBar(
title: Text(t.transactions.detail.title),
),
body: const Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: ExpenseScheduleDetailView(),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,26 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:suito/i18n/translations.g.dart';
import 'package:suito/src/common_widgets/async_value_widget.dart';
import 'package:suito/src/common_widgets/currency_input_field.dart';
import 'package:suito/src/common_widgets/text_input_field.dart';
import 'package:suito/src/common_widgets/transition_text_field.dart';
import 'package:suito/src/constants/app_sizes.dart';
import 'package:suito/src/features/schedules/services/expense/expense_schedule.dart';
import 'package:suito/src/features/schedules/services/expense/expense_schedule_form_controller.dart';
import 'package:suito/src/features/schedules/services/expense/submit_expense_schedule_controller.dart';
import 'package:suito/src/features/transaction_attributes/services/transaction_attribute_entry.dart';
import 'package:suito/src/features/transaction_attributes/services/transaction_attribute_service.dart';
import 'package:suito/src/features/transactions/services/expense/expense_form_controller.dart';
import 'package:suito/src/formz/amount.dart';
import 'package:suito/src/formz/title.dart' as stitle;
import 'package:suito/src/routing/app_router.dart';
import 'package:suito/src/utils/currency_formatter.dart';

class ExpenseScheduleDetailView extends ConsumerWidget {
final String? expenseScheduleID;

const ExpenseScheduleDetailView({required this.expenseScheduleID, super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final expenseScheduleValue =
ref.watch(expenseScheduleFutureProvider(id: expenseScheduleID));

return AsyncValueWidget<ExpenseSchedule>(
value: expenseScheduleValue,
data: (expenseSchedule) =>
_ExpenseScheduleDetailViewContents(expenseSchedule: expenseSchedule),
);
}
}

class _ExpenseScheduleDetailViewContents extends ConsumerWidget {
final ExpenseSchedule expenseSchedule;

const _ExpenseScheduleDetailViewContents({required this.expenseSchedule});
const ExpenseScheduleDetailView({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final controller = ref
.watch(expenseScheduleFormControllerProvider(expenseSchedule).notifier);
final schedule =
ref.watch(expenseScheduleFormControllerProvider(expenseSchedule));
final controller = ref.watch(expenseFormControllerProvider.notifier);
final schedule = ref.watch(expenseFormControllerProvider);

return SingleChildScrollView(
child: ListBody(
Expand All @@ -68,18 +44,16 @@ class _ExpenseScheduleDetailViewContents extends ConsumerWidget {
initialValue: schedule.category,
labelText: t.transactions.detail.inputLabels.category,
route: AppRoute.attribute,
onTap: () => ref
.read(transactionAttributeTypeProvider.notifier)
.state = TransactionAttributeType.category,
onTap: () => controller
.selectAttributeType(TransactionAttributeType.category),
onChanged: controller.onChangeCategory),
gapH12,
TransitionTextField<AttributeEntry>(
initialValue: schedule.location,
labelText: t.transactions.detail.inputLabels.location,
route: AppRoute.attribute,
onTap: () => ref
.read(transactionAttributeTypeProvider.notifier)
.state = TransactionAttributeType.location,
onTap: () => controller
.selectAttributeType(TransactionAttributeType.location),
onChanged: controller.onChangeLocation),
gapH12,
TransitionTextField<String>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:suito/i18n/translations.g.dart';

import 'income_schedule_detail_view.dart';

class IncomeScheduleDetailScreen extends ConsumerWidget {
const IncomeScheduleDetailScreen({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: AppBar(
title: Text(t.transactions.detail.title),
),
body: const Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: IncomeScheduleDetailView(),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,24 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:suito/i18n/translations.g.dart';
import 'package:suito/src/common_widgets/async_value_widget.dart';
import 'package:suito/src/common_widgets/currency_input_field.dart';
import 'package:suito/src/common_widgets/transition_text_field.dart';
import 'package:suito/src/constants/app_sizes.dart';
import 'package:suito/src/features/schedules/services/income/income_schedule.dart';
import 'package:suito/src/features/schedules/services/income/income_schedule_form_controller.dart';
import 'package:suito/src/features/schedules/services/income/submit_income_schedule_controller.dart';
import 'package:suito/src/features/transaction_attributes/services/transaction_attribute_entry.dart';
import 'package:suito/src/features/transaction_attributes/services/transaction_attribute_service.dart';
import 'package:suito/src/features/transactions/services/income/income_form_controller.dart';
import 'package:suito/src/formz/amount.dart';
import 'package:suito/src/routing/app_router.dart';
import 'package:suito/src/utils/currency_formatter.dart';

class IncomeScheduleDetailView extends ConsumerWidget {
final String? incomeScheduleID;

const IncomeScheduleDetailView({required this.incomeScheduleID, super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final incomeScheduleValue =
ref.watch(incomeScheduleFutureProvider(id: incomeScheduleID));

return AsyncValueWidget<IncomeSchedule>(
value: incomeScheduleValue,
data: (incomeSchedule) =>
_IncomeScheduleDetailViewContents(incomeSchedule: incomeSchedule),
);
}
}

class _IncomeScheduleDetailViewContents extends ConsumerWidget {
final IncomeSchedule incomeSchedule;

const _IncomeScheduleDetailViewContents({required this.incomeSchedule});
const IncomeScheduleDetailView({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final controller = ref
.watch(incomeScheduleFormControllerProvider(incomeSchedule).notifier);
final schedule =
ref.watch(incomeScheduleFormControllerProvider(incomeSchedule));
final controller = ref.watch(incomeFormControllerProvider.notifier);
final schedule = ref.watch(incomeFormControllerProvider);

return SingleChildScrollView(
child: ListBody(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:suito/i18n/translations.g.dart';
import 'package:suito/src/constants/app_sizes.dart';
import 'package:suito/src/features/transactions/services/transaction/transaction_detail_navigator.dart';

class SchedulesExpenseListHeader extends ConsumerWidget {
const SchedulesExpenseListHeader({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final navigator = ref.watch(transactionDetailNavigatorProvider.notifier);

return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Container(
color: Colors.white,
child: Column(
children: [
Row(
children: [
gapW12,
Text(
t.schedules.expansionTile.expenseHeader,
),
IconButton(
icon: const Icon(
Icons.add_circle,
color: Colors.red,
),
onPressed: navigator.goNewExpenseSchedule),
],
),
const Divider(
height: 0,
),
],
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:openapi/openapi.dart';
import 'package:suito/i18n/translations.g.dart';
import 'package:suito/src/common_widgets/custom_dismissible.dart';
import 'package:suito/src/constants/app_sizes.dart';
import 'package:suito/src/features/schedules/services/expense/delete_expense_schedule_controller.dart';
import 'package:suito/src/features/transactions/services/transaction/transaction_detail_navigator.dart';
import 'package:suito/src/utils/currency_formatter.dart';

class SchedulesExpenseListItem extends ConsumerWidget {
final TransactionSchedule item;

const SchedulesExpenseListItem({super.key, required this.item});

@override
Widget build(BuildContext context, WidgetRef ref) {
final currencyFormatter = ref.watch(currencyFormatterProvider);
final navigator = ref.watch(transactionDetailNavigatorProvider.notifier);

return CustomDismissible(
key: Key(item.id),
onDismissed: (direction) async {
final ScaffoldMessengerState state = ScaffoldMessenger.of(context);

await ref
.read(deleteExpenseScheduleControllerProvider.notifier)
.deleteExpenseSchedule(item.id);

// Show a snackbar.
state.showSnackBar(
SnackBar(content: Text(t.general.dismissible.snackBar)));
},
child: GestureDetector(
onTap: () => navigator.goFetchExpenseSchedule(item.id),
child: Container(
color: Colors.white,
child: SizedBox(
height: 50,
child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Text(item.title),
gapW64,
gapW64,
SizedBox(
width: 64,
child: Align(
alignment: Alignment.centerRight,
child: Text(currencyFormatter.format(item.amount),
style: const TextStyle(
color: Colors.green,
)))),
gapW32
]),
),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:suito/i18n/translations.g.dart';
import 'package:suito/src/constants/app_sizes.dart';
import 'package:suito/src/features/transactions/services/transaction/transaction_detail_navigator.dart';

class SchedulesIncomeListHeader extends ConsumerWidget {
const SchedulesIncomeListHeader({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final navigator = ref.watch(transactionDetailNavigatorProvider.notifier);

return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Container(
color: Colors.white,
child: Column(
children: [
Row(
children: [
gapW12,
Text(
t.schedules.expansionTile.incomeHeader,
),
IconButton(
icon: const Icon(
Icons.add_circle,
color: Colors.green,
),
onPressed: navigator.goNewIncomeSchedule),
],
),
const Divider(
height: 0,
),
],
),
),
);
}
}
Loading

0 comments on commit 9c0d178

Please sign in to comment.