forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage_picker.dart
More file actions
85 lines (78 loc) · 3.23 KB
/
Copy pathlanguage_picker.dart
File metadata and controls
85 lines (78 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:omi/providers/locale_provider.dart';
import 'package:omi/utils/l10n_extensions.dart';
class LanguagePickerTile extends StatelessWidget {
const LanguagePickerTile({super.key});
@override
Widget build(BuildContext context) {
return Consumer<LocaleProvider>(
builder: (context, localeProvider, child) {
final currentLocale = localeProvider.locale;
final displayName =
currentLocale != null ? LocaleProvider.getDisplayName(currentLocale) : context.l10n.systemDefault;
return ListTile(
title: Text(context.l10n.language, style: const TextStyle(color: Colors.white)),
subtitle: Text(displayName, style: TextStyle(color: Colors.grey.shade400)),
trailing: const Icon(Icons.chevron_right, color: Colors.grey),
onTap: () => _showLanguagePicker(context, localeProvider),
);
},
);
}
void _showLanguagePicker(BuildContext context, LocaleProvider localeProvider) {
final supportedLocales = LocaleProvider.supportedLocales;
final currentLocale = localeProvider.locale;
showModalBottomSheet(
context: context,
backgroundColor: const Color(0xFF1C1C1E),
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
builder: (context) {
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
margin: const EdgeInsets.only(top: 12, bottom: 16),
width: 36,
height: 4,
decoration: BoxDecoration(color: const Color(0xFF3C3C43), borderRadius: BorderRadius.circular(2)),
),
Text(
context.l10n.selectLanguage,
style: const TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.w600),
),
const SizedBox(height: 16),
Flexible(
child: ListView.builder(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
itemCount: supportedLocales.length,
itemBuilder: (context, index) {
final locale = supportedLocales[index];
final isSelected = currentLocale?.languageCode == locale.languageCode;
return ListTile(
title: Text(
LocaleProvider.getDisplayName(locale),
style: TextStyle(
color: isSelected ? Colors.white : const Color(0xFF8E8E93),
fontWeight: isSelected ? FontWeight.w500 : FontWeight.w400,
),
),
trailing: isSelected ? const Icon(Icons.check, color: Colors.white, size: 20) : null,
onTap: () {
localeProvider.setLocale(locale);
Navigator.pop(context);
},
);
},
),
),
const SizedBox(height: 16),
],
),
);
},
);
}
}