forked from baron/baron-sso
uf 액션 토스트 공통화 및 SnackBar 제거
This commit is contained in:
234
userfront/lib/core/ui/toast_service.dart
Normal file
234
userfront/lib/core/ui/toast_service.dart
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
enum ToastType { success, error, info }
|
||||||
|
|
||||||
|
class _ToastItem {
|
||||||
|
const _ToastItem({
|
||||||
|
required this.id,
|
||||||
|
required this.message,
|
||||||
|
required this.type,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String id;
|
||||||
|
final String message;
|
||||||
|
final ToastType type;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ToastService {
|
||||||
|
static const Duration _displayDuration = Duration(milliseconds: 3000);
|
||||||
|
static final ValueNotifier<List<_ToastItem>> _toasts =
|
||||||
|
ValueNotifier<List<_ToastItem>>(<_ToastItem>[]);
|
||||||
|
|
||||||
|
static void success(String message) {
|
||||||
|
show(message, type: ToastType.success);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void error(String message) {
|
||||||
|
show(message, type: ToastType.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void info(String message) {
|
||||||
|
show(message, type: ToastType.info);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void show(String message, {ToastType type = ToastType.success}) {
|
||||||
|
final trimmed = message.trim();
|
||||||
|
if (trimmed.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final item = _ToastItem(
|
||||||
|
id: '${DateTime.now().microsecondsSinceEpoch}-${_toasts.value.length}',
|
||||||
|
message: trimmed,
|
||||||
|
type: type,
|
||||||
|
);
|
||||||
|
|
||||||
|
_toasts.value = [..._toasts.value, item];
|
||||||
|
|
||||||
|
unawaited(
|
||||||
|
Future<void>.delayed(_displayDuration, () {
|
||||||
|
_remove(item.id);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _remove(String id) {
|
||||||
|
final next = _toasts.value.where((toast) => toast.id != id).toList();
|
||||||
|
if (next.length == _toasts.value.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_toasts.value = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ToastViewport extends StatelessWidget {
|
||||||
|
const ToastViewport({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return IgnorePointer(
|
||||||
|
ignoring: true,
|
||||||
|
child: SafeArea(
|
||||||
|
child: ValueListenableBuilder<List<_ToastItem>>(
|
||||||
|
valueListenable: ToastService._toasts,
|
||||||
|
builder: (context, toasts, _) {
|
||||||
|
if (toasts.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
final media = MediaQuery.of(context);
|
||||||
|
final width = math.min(320.0, media.size.width - 32);
|
||||||
|
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.bottomRight,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 16, bottom: 16),
|
||||||
|
child: SizedBox(
|
||||||
|
width: width > 0 ? width : 320,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
for (final toast in toasts)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8),
|
||||||
|
child: _ToastCard(item: toast),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ToastCard extends StatefulWidget {
|
||||||
|
const _ToastCard({required this.item});
|
||||||
|
|
||||||
|
final _ToastItem item;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_ToastCard> createState() => _ToastCardState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ToastCardState extends State<_ToastCard> {
|
||||||
|
bool _visible = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (!mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
_visible = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final scheme = _toastColorScheme(widget.item.type);
|
||||||
|
final icon = _toastIcon(widget.item.type);
|
||||||
|
|
||||||
|
return AnimatedSlide(
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
offset: _visible ? Offset.zero : const Offset(1, 0),
|
||||||
|
child: AnimatedOpacity(
|
||||||
|
duration: const Duration(milliseconds: 220),
|
||||||
|
opacity: _visible ? 1 : 0,
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: scheme.background,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: scheme.border),
|
||||||
|
boxShadow: const [
|
||||||
|
BoxShadow(
|
||||||
|
color: Color(0x26000000),
|
||||||
|
blurRadius: 16,
|
||||||
|
offset: Offset(0, 6),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 20, color: scheme.foreground),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
widget.item.message,
|
||||||
|
style: TextStyle(
|
||||||
|
color: scheme.foreground,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
height: 1.2,
|
||||||
|
decoration: TextDecoration.none,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ToastColorScheme _toastColorScheme(ToastType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ToastType.success:
|
||||||
|
return const _ToastColorScheme(
|
||||||
|
background: Color(0xFFECFDF5),
|
||||||
|
border: Color(0xFFA7F3D0),
|
||||||
|
foreground: Color(0xFF065F46),
|
||||||
|
);
|
||||||
|
case ToastType.error:
|
||||||
|
return const _ToastColorScheme(
|
||||||
|
background: Color(0xFFFFF1F2),
|
||||||
|
border: Color(0xFFFDA4AF),
|
||||||
|
foreground: Color(0xFF9F1239),
|
||||||
|
);
|
||||||
|
case ToastType.info:
|
||||||
|
return const _ToastColorScheme(
|
||||||
|
background: Color(0xFFEFF6FF),
|
||||||
|
border: Color(0xFFBFDBFE),
|
||||||
|
foreground: Color(0xFF1E40AF),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IconData _toastIcon(ToastType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ToastType.success:
|
||||||
|
return Icons.check_circle_outline;
|
||||||
|
case ToastType.error:
|
||||||
|
return Icons.error_outline;
|
||||||
|
case ToastType.info:
|
||||||
|
return Icons.info_outline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ToastColorScheme {
|
||||||
|
const _ToastColorScheme({
|
||||||
|
required this.background,
|
||||||
|
required this.border,
|
||||||
|
required this.foreground,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Color background;
|
||||||
|
final Color border;
|
||||||
|
final Color foreground;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import '../../../../core/services/auth_proxy_service.dart';
|
import '../../../../core/services/auth_proxy_service.dart';
|
||||||
import '../../../../core/i18n/locale_utils.dart';
|
import '../../../../core/i18n/locale_utils.dart';
|
||||||
|
import '../../../../core/ui/toast_service.dart';
|
||||||
|
|
||||||
class CreateUserScreen extends StatefulWidget {
|
class CreateUserScreen extends StatefulWidget {
|
||||||
const CreateUserScreen({super.key});
|
const CreateUserScreen({super.key});
|
||||||
@@ -86,12 +87,7 @@ class _CreateUserScreenState extends State<CreateUserScreen> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error('Invalid Password. Access Denied.');
|
||||||
const SnackBar(
|
|
||||||
content: Text('Invalid Password. Access Denied.'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.go(buildLocalizedHomePath(Uri.base)); // Kick out
|
context.go(buildLocalizedHomePath(Uri.base)); // Kick out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,12 +140,7 @@ class _CreateUserScreenState extends State<CreateUserScreen> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.success('User created successfully!');
|
||||||
const SnackBar(
|
|
||||||
content: Text('User created successfully!'),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
_formKey.currentState!.reset();
|
_formKey.currentState!.reset();
|
||||||
_loginIdController.clear();
|
_loginIdController.clear();
|
||||||
_emailController.clear();
|
_emailController.clear();
|
||||||
@@ -158,9 +149,7 @@ class _CreateUserScreenState extends State<CreateUserScreen> {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error('Error: $e');
|
||||||
SnackBar(content: Text('Error: $e'), backgroundColor: Colors.red),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (mounted) setState(() => _isLoading = false);
|
if (mounted) setState(() => _isLoading = false);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import '../../../../core/services/auth_proxy_service.dart';
|
import '../../../../core/services/auth_proxy_service.dart';
|
||||||
import '../../../../core/i18n/locale_utils.dart';
|
import '../../../../core/i18n/locale_utils.dart';
|
||||||
|
import '../../../../core/ui/toast_service.dart';
|
||||||
|
|
||||||
class UserManagementScreen extends StatefulWidget {
|
class UserManagementScreen extends StatefulWidget {
|
||||||
const UserManagementScreen({super.key});
|
const UserManagementScreen({super.key});
|
||||||
@@ -108,12 +109,7 @@ class _UserManagementScreenState extends State<UserManagementScreen>
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error('Invalid Password');
|
||||||
const SnackBar(
|
|
||||||
content: Text('Invalid Password'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.go(buildLocalizedHomePath(Uri.base));
|
context.go(buildLocalizedHomePath(Uri.base));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,16 +339,12 @@ class _UserManagementScreenState extends State<UserManagementScreen>
|
|||||||
// --- UI Helpers ---
|
// --- UI Helpers ---
|
||||||
void _showError(String msg) {
|
void _showError(String msg) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(
|
ToastService.error(msg);
|
||||||
context,
|
|
||||||
).showSnackBar(SnackBar(content: Text(msg), backgroundColor: Colors.red));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showSuccess(String msg) {
|
void _showSuccess(String msg) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(
|
ToastService.success(msg);
|
||||||
context,
|
|
||||||
).showSnackBar(SnackBar(content: Text(msg), backgroundColor: Colors.green));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:userfront/i18n.dart';
|
|||||||
import 'package:userfront/core/i18n/locale_utils.dart';
|
import 'package:userfront/core/i18n/locale_utils.dart';
|
||||||
import 'package:userfront/core/services/auth_proxy_service.dart';
|
import 'package:userfront/core/services/auth_proxy_service.dart';
|
||||||
import 'package:userfront/core/services/web_window.dart';
|
import 'package:userfront/core/services/web_window.dart';
|
||||||
|
import 'package:userfront/core/ui/toast_service.dart';
|
||||||
|
|
||||||
class ConsentScreen extends StatefulWidget {
|
class ConsentScreen extends StatefulWidget {
|
||||||
final String consentChallenge;
|
final String consentChallenge;
|
||||||
@@ -187,16 +188,11 @@ class _ConsentScreenState extends State<ConsentScreen> {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() => _isSubmitting = false);
|
setState(() => _isSubmitting = false);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error(
|
||||||
SnackBar(
|
tr(
|
||||||
content: Text(
|
'msg.userfront.consent.cancel.error',
|
||||||
tr(
|
fallback: 'An error occurred while cancelling consent: {{error}}',
|
||||||
'msg.userfront.consent.cancel.error',
|
params: {'error': '$e'},
|
||||||
fallback:
|
|
||||||
'An error occurred while cancelling consent: {{error}}',
|
|
||||||
params: {'error': '$e'},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -419,7 +415,7 @@ class _ConsentScreenState extends State<ConsentScreen> {
|
|||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
tr('ui.userfront.consent.accept'),
|
tr('ui.userfront.consent.accept'),
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../../core/services/auth_proxy_service.dart';
|
import '../../../core/services/auth_proxy_service.dart';
|
||||||
|
import '../../../core/ui/toast_service.dart';
|
||||||
import 'package:userfront/i18n.dart';
|
import 'package:userfront/i18n.dart';
|
||||||
|
|
||||||
class ForgotPasswordScreen extends StatefulWidget {
|
class ForgotPasswordScreen extends StatefulWidget {
|
||||||
@@ -46,12 +47,7 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
|||||||
drySend: _drySendEnabled,
|
drySend: _drySendEnabled,
|
||||||
);
|
);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.success(tr('msg.userfront.forgot.sent'));
|
||||||
SnackBar(
|
|
||||||
content: Text(tr('msg.userfront.forgot.sent')),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -68,9 +64,7 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showError(String message) {
|
void _showError(String message) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error(message);
|
||||||
SnackBar(content: Text(message), backgroundColor: Colors.red),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _parseBoolParam(String? value) {
|
bool _parseBoolParam(String? value) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import '../domain/cookie_session_policy.dart';
|
|||||||
import '../domain/login_link_route_policy.dart';
|
import '../domain/login_link_route_policy.dart';
|
||||||
import '../../profile/domain/notifiers/profile_notifier.dart';
|
import '../../profile/domain/notifiers/profile_notifier.dart';
|
||||||
import '../../../core/services/web_window.dart';
|
import '../../../core/services/web_window.dart';
|
||||||
|
import '../../../core/ui/toast_service.dart';
|
||||||
|
|
||||||
class LoginScreen extends ConsumerStatefulWidget {
|
class LoginScreen extends ConsumerStatefulWidget {
|
||||||
final String? verificationToken;
|
final String? verificationToken;
|
||||||
@@ -1153,9 +1154,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
|||||||
|
|
||||||
void _showError(String message) {
|
void _showError(String message) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error(message);
|
||||||
SnackBar(content: Text(message), backgroundColor: Colors.red),
|
|
||||||
);
|
|
||||||
try {
|
try {
|
||||||
AuthProxyService.logError(message);
|
AuthProxyService.logError(message);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -1165,9 +1164,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
|||||||
|
|
||||||
void _showInfo(String message) {
|
void _showInfo(String message) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.success(message);
|
||||||
SnackBar(content: Text(message), backgroundColor: Colors.green),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _logTokenDetails(String jwt) {
|
void _logTokenDetails(String jwt) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:userfront/i18n.dart';
|
import 'package:userfront/i18n.dart';
|
||||||
|
import 'package:userfront/core/ui/toast_service.dart';
|
||||||
|
|
||||||
import 'qr_scan_route.dart';
|
import 'qr_scan_route.dart';
|
||||||
|
|
||||||
@@ -23,15 +24,8 @@ class _QRScanScreenState extends State<QRScanScreen> {
|
|||||||
void _submit() {
|
void _submit() {
|
||||||
final raw = _controller.text.trim();
|
final raw = _controller.text.trim();
|
||||||
if (raw.isEmpty) {
|
if (raw.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.info(
|
||||||
SnackBar(
|
tr('msg.userfront.qr.permission_required', fallback: '카메라 권한이 필요합니다.'),
|
||||||
content: Text(
|
|
||||||
tr(
|
|
||||||
'msg.userfront.qr.permission_required',
|
|
||||||
fallback: '카메라 권한이 필요합니다.',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import '../../../core/i18n/locale_utils.dart';
|
import '../../../core/i18n/locale_utils.dart';
|
||||||
import '../../../core/services/auth_proxy_service.dart';
|
import '../../../core/services/auth_proxy_service.dart';
|
||||||
|
import '../../../core/ui/toast_service.dart';
|
||||||
import 'package:userfront/i18n.dart';
|
import 'package:userfront/i18n.dart';
|
||||||
|
|
||||||
class ResetPasswordScreen extends StatefulWidget {
|
class ResetPasswordScreen extends StatefulWidget {
|
||||||
@@ -84,12 +85,7 @@ class _ResetPasswordScreenState extends State<ResetPasswordScreen> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.success(tr('msg.userfront.reset.success'));
|
||||||
SnackBar(
|
|
||||||
content: Text(tr('msg.userfront.reset.success')),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.go(buildLocalizedSigninPath(Uri.base));
|
context.go(buildLocalizedSigninPath(Uri.base));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -109,9 +105,7 @@ class _ResetPasswordScreenState extends State<ResetPasswordScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showError(String message) {
|
void _showError(String message) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error(message);
|
||||||
SnackBar(content: Text(message), backgroundColor: Colors.red),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String _buildPolicyDescription() {
|
String _buildPolicyDescription() {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import '../../../../core/services/http_client.dart';
|
|||||||
import '../../../../core/i18n/locale_utils.dart';
|
import '../../../../core/i18n/locale_utils.dart';
|
||||||
import '../../../../core/widgets/language_selector.dart';
|
import '../../../../core/widgets/language_selector.dart';
|
||||||
import '../../../../core/ui/layout_breakpoints.dart';
|
import '../../../../core/ui/layout_breakpoints.dart';
|
||||||
|
import '../../../../core/ui/toast_service.dart';
|
||||||
import '../../profile/domain/notifiers/profile_notifier.dart';
|
import '../../profile/domain/notifiers/profile_notifier.dart';
|
||||||
import '../domain/dashboard_providers.dart';
|
import '../domain/dashboard_providers.dart';
|
||||||
import '../domain/models.dart' hide LinkedRp;
|
import '../domain/models.dart' hide LinkedRp;
|
||||||
@@ -104,14 +105,10 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
try {
|
try {
|
||||||
await ref.read(linkedRpsProvider.notifier).revokeRp(clientId);
|
await ref.read(linkedRpsProvider.notifier).revokeRp(clientId);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.success(
|
||||||
SnackBar(
|
tr(
|
||||||
content: Text(
|
'msg.userfront.dashboard.revoke.success',
|
||||||
tr(
|
params: {'app': appName},
|
||||||
'msg.userfront.dashboard.revoke.success',
|
|
||||||
params: {'app': appName},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -121,15 +118,8 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error(
|
||||||
SnackBar(
|
tr('msg.userfront.dashboard.revoke.error', params: {'error': '$e'}),
|
||||||
content: Text(
|
|
||||||
tr(
|
|
||||||
'msg.userfront.dashboard.revoke.error',
|
|
||||||
params: {'error': '$e'},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -547,12 +537,8 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
: () async {
|
: () async {
|
||||||
await Clipboard.setData(ClipboardData(text: approvedSessionId));
|
await Clipboard.setData(ClipboardData(text: approvedSessionId));
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.info(
|
||||||
SnackBar(
|
tr('msg.userfront.dashboard.session_id_copied'),
|
||||||
content: Text(
|
|
||||||
tr('msg.userfront.dashboard.session_id_copied'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -626,12 +612,8 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
: () async {
|
: () async {
|
||||||
await Clipboard.setData(ClipboardData(text: approvedSessionId));
|
await Clipboard.setData(ClipboardData(text: approvedSessionId));
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.info(
|
||||||
SnackBar(
|
tr('msg.userfront.dashboard.session_id_copied'),
|
||||||
content: Text(
|
|
||||||
tr('msg.userfront.dashboard.session_id_copied'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1280,7 +1262,6 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
cursor: SystemMouseCursors.click,
|
cursor: SystemMouseCursors.click,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final messenger = ScaffoldMessenger.of(context);
|
|
||||||
final itemUrl = item.url;
|
final itemUrl = item.url;
|
||||||
if (itemUrl != null && itemUrl.isNotEmpty) {
|
if (itemUrl != null && itemUrl.isNotEmpty) {
|
||||||
final uri = Uri.parse(itemUrl);
|
final uri = Uri.parse(itemUrl);
|
||||||
@@ -1290,18 +1271,10 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
await launchUrl(uri);
|
await launchUrl(uri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
messenger.showSnackBar(
|
ToastService.error(tr('msg.userfront.dashboard.link_open_error'));
|
||||||
SnackBar(
|
|
||||||
content: Text(tr('msg.userfront.dashboard.link_open_error')),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
messenger.showSnackBar(
|
ToastService.info(tr('msg.userfront.dashboard.link_missing'));
|
||||||
SnackBar(
|
|
||||||
content: Text(tr('msg.userfront.dashboard.link_missing')),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: opaqueCard,
|
child: opaqueCard,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import '../../../../core/notifiers/auth_notifier.dart';
|
|||||||
import '../../../../core/i18n/locale_utils.dart';
|
import '../../../../core/i18n/locale_utils.dart';
|
||||||
import '../../../../core/services/auth_token_store.dart';
|
import '../../../../core/services/auth_token_store.dart';
|
||||||
import '../../../../core/ui/layout_breakpoints.dart';
|
import '../../../../core/ui/layout_breakpoints.dart';
|
||||||
|
import '../../../../core/ui/toast_service.dart';
|
||||||
import '../../../../core/widgets/language_selector.dart';
|
import '../../../../core/widgets/language_selector.dart';
|
||||||
import '../../data/models/user_profile_model.dart';
|
import '../../data/models/user_profile_model.dart';
|
||||||
import '../../domain/notifiers/profile_notifier.dart';
|
import '../../domain/notifiers/profile_notifier.dart';
|
||||||
@@ -202,21 +203,15 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
_isVerifying = false;
|
_isVerifying = false;
|
||||||
});
|
});
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.info(tr('msg.userfront.profile.phone.code_sent'));
|
||||||
SnackBar(content: Text(tr('msg.userfront.profile.phone.code_sent'))),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() => _isVerifying = false);
|
setState(() => _isVerifying = false);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error(
|
||||||
SnackBar(
|
tr(
|
||||||
content: Text(
|
'msg.userfront.profile.phone.send_failed',
|
||||||
tr(
|
params: {'error': e.toString()},
|
||||||
'msg.userfront.profile.phone.send_failed',
|
|
||||||
params: {'error': e.toString()},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -236,21 +231,15 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
_isVerifying = false;
|
_isVerifying = false;
|
||||||
});
|
});
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.success(tr('msg.userfront.profile.phone.verified'));
|
||||||
SnackBar(content: Text(tr('msg.userfront.profile.phone.verified'))),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() => _isVerifying = false);
|
setState(() => _isVerifying = false);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.error(
|
||||||
SnackBar(
|
tr(
|
||||||
content: Text(
|
'msg.userfront.profile.phone.verify_failed',
|
||||||
tr(
|
params: {'error': e.toString()},
|
||||||
'msg.userfront.profile.phone.verify_failed',
|
|
||||||
params: {'error': e.toString()},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -302,8 +291,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
_newPasswordController?.clear();
|
_newPasswordController?.clear();
|
||||||
_confirmPasswordController?.clear();
|
_confirmPasswordController?.clear();
|
||||||
setState(() {
|
setState(() {
|
||||||
_passwordSuccess = tr('msg.userfront.profile.password.changed');
|
_passwordSuccess = null;
|
||||||
});
|
});
|
||||||
|
ToastService.success(tr('msg.userfront.profile.password.changed'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
final message = e.toString().replaceFirst('Exception: ', '');
|
final message = e.toString().replaceFirst('Exception: ', '');
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -312,6 +302,12 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
params: {'error': message},
|
params: {'error': message},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
ToastService.error(
|
||||||
|
tr(
|
||||||
|
'msg.userfront.profile.password.change_failed',
|
||||||
|
params: {'error': message},
|
||||||
|
),
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => _isPasswordSaving = false);
|
setState(() => _isPasswordSaving = false);
|
||||||
@@ -338,7 +334,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
_debugLog('save_skip', reason: 'saving_in_flight');
|
_debugLog('save_skip', reason: 'saving_in_flight');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_fieldSaveError = null;
|
_fieldSaveError = null;
|
||||||
});
|
});
|
||||||
@@ -411,7 +407,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_isSavingField = true;
|
_isSavingField = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
_debugLog('save_dispatch', field: currentField, changed: true);
|
_debugLog('save_dispatch', field: currentField, changed: true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -431,9 +427,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
_editingField = null;
|
_editingField = null;
|
||||||
});
|
});
|
||||||
_debugLog('save_success', field: currentField);
|
_debugLog('save_success', field: currentField);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ToastService.success(tr('msg.userfront.profile.update_success'));
|
||||||
SnackBar(content: Text(tr('msg.userfront.profile.update_success'))),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_debugLog('save_failed', field: currentField, reason: e.toString());
|
_debugLog('save_failed', field: currentField, reason: e.toString());
|
||||||
@@ -711,7 +705,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
key: Key('profile-$field-cancel-button'),
|
key: Key('profile-$field-cancel-button'),
|
||||||
onPressed: isUpdating || _isSavingField ? null : () => _cancelEditing(profile),
|
onPressed: isUpdating || _isSavingField
|
||||||
|
? null
|
||||||
|
: () => _cancelEditing(profile),
|
||||||
child: Text(tr('ui.common.cancel')),
|
child: Text(tr('ui.common.cancel')),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -798,7 +794,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onPressed: isUpdating || _isSavingField ? null : () => _cancelEditing(profile),
|
onPressed: isUpdating || _isSavingField
|
||||||
|
? null
|
||||||
|
: () => _cancelEditing(profile),
|
||||||
child: Text(tr('ui.common.cancel')),
|
child: Text(tr('ui.common.cancel')),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import 'core/i18n/locale_gate.dart';
|
|||||||
import 'core/i18n/locale_registry.dart';
|
import 'core/i18n/locale_registry.dart';
|
||||||
import 'core/i18n/locale_utils.dart';
|
import 'core/i18n/locale_utils.dart';
|
||||||
import 'core/i18n/toml_asset_loader.dart';
|
import 'core/i18n/toml_asset_loader.dart';
|
||||||
|
import 'core/ui/toast_service.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'features/auth/presentation/consent_screen.dart';
|
import 'features/auth/presentation/consent_screen.dart';
|
||||||
import 'i18n.dart';
|
import 'i18n.dart';
|
||||||
@@ -370,6 +371,11 @@ class BaronSSOApp extends StatelessWidget {
|
|||||||
localizationsDelegates: delegates,
|
localizationsDelegates: delegates,
|
||||||
supportedLocales: supportedLocales,
|
supportedLocales: supportedLocales,
|
||||||
locale: locale,
|
locale: locale,
|
||||||
|
builder: (context, child) {
|
||||||
|
return Stack(
|
||||||
|
children: [if (child != null) child, const ToastViewport()],
|
||||||
|
);
|
||||||
|
},
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(
|
colorScheme: ColorScheme.fromSeed(
|
||||||
seedColor: const Color(0xFF1A1F2C), // Dark Navy/Black base
|
seedColor: const Color(0xFF1A1F2C), // Dark Navy/Black base
|
||||||
|
|||||||
Reference in New Issue
Block a user