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.
HMG_QLine/lib/views/common_widgets/date_display_widget.dart

60 lines
2.3 KiB
Dart

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
class SimpleDateDisplay extends StatelessWidget {
final bool isForArabic;
SimpleDateDisplay({super.key, required this.isForArabic});
final List<String> _englishWeekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
final List<String> _englishMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// Note: For Arabic, the full month names are commonly used in this context.
final List<String> _arabicWeekdays = ['الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت', 'الأحد'];
final List<String> _arabicMonths = ['يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'];
String _toArabicDigits(int number) {
const Map<String, String> arabicDigits = {
'0': '٠',
'1': '١',
'2': '٢',
'3': '٣',
'4': '٤',
'5': '٥',
'6': '٦',
'7': '٧',
'8': '٨',
'9': '٩',
};
return number.toString().split('').map((char) => arabicDigits[char] ?? char).join();
}
@override
Widget build(BuildContext context) {
final DateTime now = DateTime.now();
// English formatting
final String englishDayOfWeek = _englishWeekdays[now.weekday - 1];
final String englishMonthAbbr = _englishMonths[now.month - 1];
final String englishDateString = '$englishDayOfWeek | ${now.day} $englishMonthAbbr';
// Arabic formatting
final String arabicDayOfWeek = _arabicWeekdays[now.weekday - 1];
final String arabicDayDigits = _toArabicDigits(now.day);
final String arabicMonthName = _arabicMonths[now.month - 1];
final String arabicDateString = '$arabicDayOfWeek | $arabicDayDigits $arabicMonthName';
return isForArabic // Use widget.isForArabic to access the property
? Text(
arabicDateString,
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
textDirection: TextDirection.rtl, // Crucial for Arabic text
)
: Text(
englishDateString,
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
);
}
}