Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
language_selector.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:easy_localization/easy_localization.dart';
3
4class LanguageSelector extends StatefulWidget {
5 final Color? primaryColor;
6 final Color? textColor;
7 final double? borderRadius;
8
10 super.key,
11 this.primaryColor,
12 this.textColor,
13 this.borderRadius,
14 });
15
16 @override
17 State<LanguageSelector> createState() => _ModernLanguageSelectorState();
18}
19
20class _ModernLanguageSelectorState extends State<LanguageSelector> with SingleTickerProviderStateMixin {
21 late AnimationController _controller;
22 late Animation<double> _rotationAnimation;
23 bool _isOpen = false;
24
25 @override
26 void initState() {
27 super.initState();
28 _controller = AnimationController(
29 duration: const Duration(milliseconds: 300),
30 vsync: this,
31 );
32 _rotationAnimation = Tween<double>(begin: 0, end: 0.5).animate(
33 CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
34 );
35 }
36
37 @override
38 void dispose() {
39 _controller.dispose();
40 super.dispose();
41 }
42
44 setState(() {
46 if (_isOpen) {
47 _controller.forward();
48 } else {
49 _controller.reverse();
50 }
51 });
52 }
53
54 @override
55 Widget build(BuildContext context) {
56 final Color primaryColor = widget.primaryColor ?? Theme.of(context).primaryColor;
57 final Color textColor = widget.textColor ?? Colors.white;
58 final double borderRadius = widget.borderRadius ?? 12.0;
59
60 return Theme(
61 data: Theme.of(context).copyWith(
62 popupMenuTheme: PopupMenuThemeData(
63 elevation: 20,
64 shape: RoundedRectangleBorder(
65 borderRadius: BorderRadius.circular(borderRadius),
66 ),
67 ),
68 ),
69 child: PopupMenuButton<Locale>(
70 offset: const Offset(0, 10),
71 position: PopupMenuPosition.under,
72 onOpened: () {
73 _toggleDropdown();
74 },
75 onCanceled: () {
76 _toggleDropdown();
77 },
78 onSelected: (Locale locale) {
79 context.setLocale(locale);
80 _toggleDropdown();
81 },
82 tooltip: 'Select language',
83 child: Container(
84 padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
85 decoration: BoxDecoration(
86 color: primaryColor,
87 borderRadius: BorderRadius.circular(borderRadius),
88 boxShadow: [
89 BoxShadow(
90 color: primaryColor.withValues(alpha: 0.3),
91 blurRadius: 8,
92 offset: const Offset(0, 3),
93 ),
94 ],
95 ),
96 child: Row(
97 mainAxisSize: MainAxisSize.min,
98 children: [
99 Icon(
100 Icons.language_rounded,
101 color: textColor,
102 size: 20,
103 ),
104 const SizedBox(width: 8),
105 Text(
106 _getLanguageName(context.locale.languageCode),
107 style: TextStyle(
108 color: textColor,
109 fontWeight: FontWeight.bold,
110 ),
111 ),
112 const SizedBox(width: 4),
113 RotationTransition(
114 turns: _rotationAnimation,
115 child: Icon(
116 Icons.arrow_drop_down,
117 color: textColor,
118 ),
119 ),
120 ],
121 ),
122 ),
123 itemBuilder: (BuildContext context) => <PopupMenuEntry<Locale>>[
124 _buildLanguageMenuItem(context, 'en', 'English'),
125 _buildLanguageMenuItem(context, 'ar', 'العربية'),
126 _buildLanguageMenuItem(context, 'ur', 'اردو'),
127 ],
128 ),
129 );
130 }
131
132 PopupMenuItem<Locale> _buildLanguageMenuItem(BuildContext context, String code, String name) {
133 final bool isSelected = context.locale.languageCode == code;
134
135 return PopupMenuItem<Locale>(
136 value: Locale(code),
137 child: Container(
138 padding: const EdgeInsets.symmetric(vertical: 8),
139 child: Row(
140 mainAxisAlignment: MainAxisAlignment.spaceBetween,
141 children: [
142 Row(
143 children: [
144 // _buildLanguageFlag(code),
145 // const SizedBox(width: 12),
146 Text(
147 name,
148 style: TextStyle(
149 fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
150 fontSize: 16,
151 ),
152 ),
153 ],
154 ),
155 if (isSelected)
156 Container(
157 padding: const EdgeInsets.all(4),
158 decoration: BoxDecoration(
159 color: widget.primaryColor ?? Theme.of(context).primaryColor,
160 shape: BoxShape.circle,
161 ),
162 child: Icon(
163 Icons.check,
164 color: Colors.white,
165 size: 12,
166 ),
167 ),
168 ],
169 ),
170 ),
171 );
172 }
173
174 // Widget _buildLanguageFlag(String code) {
175 // switch (code) {
176 // case 'en':
177 // return const CircleAvatar(
178 // radius: 12,
179 // backgroundColor: Colors.transparent,
180 // child: Text('🇬🇧', style: TextStyle(fontSize: 18)),
181 // );
182 // case 'ar':
183 // return const CircleAvatar(
184 // radius: 12,
185 // backgroundColor: Colors.transparent,
186 // child: Text('🇸🇦', style: TextStyle(fontSize: 18)),
187 // );
188 // case 'ur':
189 // return const CircleAvatar(
190 // radius: 12,
191 // backgroundColor: Colors.transparent,
192 // child: Text('🇵🇰', style: TextStyle(fontSize: 18)),
193 // );
194 // default:
195 // return const CircleAvatar(
196 // radius: 12,
197 // child: Icon(Icons.language, size: 12),
198 // );
199 // }
200 // }
201
203 switch (code) {
204 case 'en':
205 return 'English';
206 case 'ar':
207 return 'العربية';
208 case 'ur':
209 return 'اردو';
210 default:
211 return 'Unknown';
212 }
213 }
214}
override void initState()
override void dispose()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
override State< LanguageSelector > createState()
final double borderRadius
const LanguageSelector({ super.key, this.primaryColor, this.textColor, this.borderRadius, })
final Color primaryColor
final Widget child
final EdgeInsets padding
class Partner String
final Color color
Definition failures.dart:1
String _getLanguageName(String code)
late Animation< double > _rotationAnimation
void _toggleDropdown()
PopupMenuItem< Locale > _buildLanguageMenuItem(BuildContext context, String code, String name)
class LanguageSelector extends StatefulWidget _controller
bool _isOpen
final String tooltip
class UnloadingCollectionItem extends StatefulWidget isSelected
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)