forked from baron/baron-sso
feat: i18n 개선 및 userfront 로그인/로케일 보완
This commit is contained in:
65
userfront/lib/core/widgets/language_selector.dart
Normal file
65
userfront/lib/core/widgets/language_selector.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:easy_localization/easy_localization.dart' hide tr;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:userfront/i18n.dart';
|
||||
|
||||
import '../i18n/locale_storage.dart';
|
||||
import '../i18n/locale_utils.dart';
|
||||
|
||||
class LanguageSelector extends StatelessWidget {
|
||||
const LanguageSelector({super.key, this.compact = false});
|
||||
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final current = context.locale.languageCode;
|
||||
final items = [
|
||||
DropdownMenuItem(
|
||||
value: 'ko',
|
||||
child: Text(tr('ui.common.language_ko')),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'en',
|
||||
child: Text(tr('ui.common.language_en', fallback: 'English')),
|
||||
),
|
||||
];
|
||||
|
||||
final iconSize = compact ? 16.0 : 18.0;
|
||||
final dropdown = DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: current,
|
||||
items: items,
|
||||
isDense: true,
|
||||
icon: Icon(Icons.arrow_drop_down, size: compact ? 18 : 20),
|
||||
onChanged: (value) async {
|
||||
if (value == null || value == current) {
|
||||
return;
|
||||
}
|
||||
LocaleStorage.write(value);
|
||||
await context.setLocale(Locale(value));
|
||||
final uri = GoRouterState.of(context).uri;
|
||||
final target = buildLocalizedPath(value, uri);
|
||||
if (context.mounted) {
|
||||
context.go(target);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: compact ? 0 : 2),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: compact ? 24 : 28),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.language, size: iconSize),
|
||||
const SizedBox(width: 6),
|
||||
dropdown,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user