Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-250] SnackBarの共通化 #142

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/core/widgets/common_snack_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

/// 共通SnackBar
class CommonSnackBar extends SnackBar {
CommonSnackBar._({
required String message,
super.action,
}) : super(
content: Text(message),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
);

static void show(
BuildContext context, {
required String message,
String? actionLabel,
VoidCallback? onActionPressed,
}) {
final action = actionLabel != null && onActionPressed != null
? SnackBarAction(
label: actionLabel,
onPressed: onActionPressed,
)
: null;

ScaffoldMessenger.of(context).showSnackBar(
CommonSnackBar._(message: message, action: action),
);
}
}
21 changes: 0 additions & 21 deletions lib/core/widgets/success_snack_bar.dart

This file was deleted.

5 changes: 3 additions & 2 deletions lib/features/auth/my_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../core/widgets/common_snack_bar.dart';
import '../../core/widgets/confirm_dialog.dart';
import '../../core/widgets/success_snack_bar.dart';
import 'auth_controller.dart';

/// マイページ
Expand Down Expand Up @@ -34,7 +35,7 @@ class MyPage extends ConsumerWidget {
.read(authControllerProvider)
.deleteUserAccount();
if (context.mounted) {
SuccessSnackBar.show(
CommonSnackBar.show(
context,
message: 'アカウントを削除しました',
);
Expand Down
13 changes: 2 additions & 11 deletions lib/features/auth/sign_in_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
// TODO(kim): アナリティクスマージ後にコメントアウトを解除
// import '../../core/analytics/analytics_service.dart';
import '../../core/themes.dart';
import '../../core/widgets/common_snack_bar.dart';
import '../photo/swipe_photo/swipe_photo_page.dart';
import 'auth_controller.dart';

Expand Down Expand Up @@ -116,19 +117,9 @@ class SignInPage extends HookConsumerWidget {
}
GoRouter.of(context).go(SwipePhotoPage.routePath);
} on Exception catch (e) {
_showSnackBar(context, 'サインインに失敗しました: $e');
CommonSnackBar.show(context, message: 'サインインに失敗しました: $e');
} finally {
isLoading.value = false;
}
}

/// スナックバーの表示
void _showSnackBar(BuildContext context, String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Colors.black,
),
);
}
}
16 changes: 6 additions & 10 deletions lib/features/photo/camera/camera_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:permission_handler/permission_handler.dart';

import '../../../core/build_context_extension.dart';
import '../../../core/widgets/common_snack_bar.dart';
import 'camera_controller.dart';
import 'camera_detail_page.dart';

Expand Down Expand Up @@ -92,16 +93,11 @@ class CameraPage extends HookConsumerWidget {
.takePictureAndSave(context);
if (!isCaptureSuccessful &&
context.mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(
const SnackBar(
content:
Text('設定画面で権限を全て許可に設定してください。'),
action: SnackBarAction(
label: '設定を開く',
onPressed: openAppSettings,
),
),
CommonSnackBar.show(
context,
message: '設定画面で権限を全て許可に設定してください。',
actionLabel: '設定を開く',
onActionPressed: openAppSettings,
);
ref.invalidate(cameraStateProvider);
}
Expand Down
Loading