You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Dart
		
	
| import 'package:flutter/material.dart';
 | |
| import 'package:hmg_patient_app_new/core/app_assets.dart';
 | |
| import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
 | |
| import 'package:hmg_patient_app_new/core/utils/utils.dart';
 | |
| import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
 | |
| import 'package:hmg_patient_app_new/theme/colors.dart';
 | |
| 
 | |
| class LanguageSelector extends StatefulWidget {
 | |
|   final String currentLanguage;
 | |
|   final ValueChanged<String> onLanguageChanged;
 | |
|   final List<Map<String, String>> languages;
 | |
|   final bool showOnlyIcon;
 | |
| 
 | |
|   const LanguageSelector({
 | |
|     super.key,
 | |
|     required this.currentLanguage,
 | |
|     required this.onLanguageChanged,
 | |
|     required this.languages,
 | |
|     required this.showOnlyIcon,
 | |
|   });
 | |
| 
 | |
|   @override
 | |
|   State<LanguageSelector> createState() => _LanguageSelectorState();
 | |
| }
 | |
| 
 | |
| class _LanguageSelectorState extends State<LanguageSelector> {
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     final currentLangData = widget.languages.firstWhere(
 | |
|       (lang) => lang['code'] == widget.currentLanguage,
 | |
|       orElse: () => {'code': 'en', 'name': 'English'},
 | |
|     );
 | |
| 
 | |
|     if (widget.showOnlyIcon) {
 | |
|       return InkWell(
 | |
|           onTap: () {
 | |
|             final newLanguage = widget.currentLanguage == 'ar' ? 'en' : 'ar';
 | |
|             print(newLanguage);
 | |
|             widget.onLanguageChanged(newLanguage);
 | |
|           },
 | |
|           child: Utils.buildSvgWithAssets(icon: AppAssets.globe_black));
 | |
|     } else {
 | |
|       return Stack(clipBehavior: Clip.none, children: [
 | |
|         Container(
 | |
|           decoration: BoxDecoration(
 | |
|             borderRadius: BorderRadius.circular(12),
 | |
|             color: AppColors.secondaryLightRedColor,
 | |
|           ),
 | |
|           child: InkWell(
 | |
|             onTap: () {
 | |
|               final newLanguage = widget.currentLanguage == 'ar' ? 'en' : 'ar';
 | |
|               widget.onLanguageChanged(newLanguage);
 | |
|             },
 | |
|             child: Container(
 | |
|               padding: EdgeInsets.all(8.h),
 | |
|               decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
 | |
|               child: Row(
 | |
|                 mainAxisSize: MainAxisSize.min,
 | |
|                 children: [
 | |
|                   Utils.buildSvgWithAssets(icon: AppAssets.language),
 | |
|                   SizedBox(width: 6.h),
 | |
|                   Text(
 | |
|                     currentLangData['name']?.toUpperCase() ?? 'EN',
 | |
|                     style: context.dynamicTextStyle(
 | |
|                       fontWeight: FontWeight.w500,
 | |
|                       fontSize: 14.fSize,
 | |
|                       color: AppColors.primaryRedColor,
 | |
|                       letterSpacing: 0.1,
 | |
|                       isLanguageSwitcher: true,
 | |
|                     ),
 | |
|                   ),
 | |
|                 ],
 | |
|               ),
 | |
|             ),
 | |
|           ),
 | |
|         ),
 | |
|       ]);
 | |
|     }
 | |
|   }
 | |
| }
 |