Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

121 linhas
3.6 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_persian_calendar/flutter_persian_calendar.dart';
  3. import 'package:qadirneyriz/config/config.dart';
  4. import 'package:shamsi_date/shamsi_date.dart';
  5. class Tools {
  6. static String combineErrorMessages(Map<dynamic, dynamic> errorJson) {
  7. final combinedMessages = <String>[];
  8. errorJson.forEach((key, value) {
  9. if (value is List) {
  10. combinedMessages.addAll(value.cast<String>());
  11. }
  12. });
  13. return combinedMessages.join('\n');
  14. }
  15. static void showCustomSnackBar(BuildContext context,
  16. {bool? isError, bool isDefault = true, required String text}) {
  17. Color backgroundColor;
  18. if (isError == true) {
  19. backgroundColor = Colors.redAccent;
  20. } else if (isError == false) {
  21. backgroundColor = Colors.green;
  22. } else {
  23. backgroundColor = Colors.blueAccent;
  24. }
  25. ScaffoldMessenger.of(context).showSnackBar(
  26. SnackBar(
  27. content: Text(
  28. text, // متن بر اساس وضعیت خطا تغییر می‌کند
  29. style: const TextStyle(
  30. fontSize: 12,
  31. color: Colors.white, // رنگ متن
  32. fontWeight: FontWeight.normal, // ضخامت متن
  33. ),
  34. ),
  35. backgroundColor: backgroundColor, // رنگ پس‌زمینه بر اساس وضعیت خطا
  36. shape: RoundedRectangleBorder(
  37. borderRadius: BorderRadius.circular(5), // گرد کردن لبه‌ها
  38. ),
  39. behavior: SnackBarBehavior.floating, // تغییر مکان نمایش به حالت شناور
  40. margin: const EdgeInsets.all(16), // فاصله از لبه‌های صفحه
  41. action: SnackBarAction(
  42. label: 'UNDO',
  43. textColor: Colors.yellow, // رنگ متن اکشن
  44. onPressed: () {},
  45. ),
  46. ),
  47. );
  48. }
  49. static String getMonthName(int month) {
  50. const months = [
  51. 'فروردین',
  52. 'اردیبهشت',
  53. 'خرداد',
  54. 'تیر',
  55. 'مرداد',
  56. 'شهریور',
  57. 'مهر',
  58. 'آبان',
  59. 'آذر',
  60. 'دی',
  61. 'بهمن',
  62. 'اسفند'
  63. ];
  64. return months[month - 1];
  65. }
  66. static PersianCalendar shamsiDateCalendarWidget(
  67. BuildContext context,
  68. Function(Jalali) onDateSelected,
  69. ) {
  70. return PersianCalendar(
  71. calendarHeight: 376,
  72. calendarWidth: 360,
  73. selectedDate: Jalali.now(),
  74. onDateChanged: (newDate) {
  75. onDateSelected(newDate); // Call the function passed to update the date
  76. },
  77. onConfirmButtonPressed: () {
  78. Navigator.pop(
  79. context); // Pop widget when user presses on confirm button
  80. },
  81. calendarStartDate: Jalali(1400, 1, 1),
  82. calendarEndDate: Jalali(1450, 1, 1),
  83. calendarTheme: PersianCalendarTheme(
  84. backgroundColor: const Color(0XFFEDF2F4),
  85. selectedColor: config.ui.mainGreen,
  86. headerBackgroundColor: const Color(0XFF8D99AE),
  87. textStyle: const TextStyle(
  88. fontSize: 14,
  89. color: Colors.black,
  90. ),
  91. selectedItemTextStyle: const TextStyle(
  92. fontSize: 14,
  93. color: Color(0XFFF2F2F2),
  94. ),
  95. confirmButtonTextStyle: const TextStyle(
  96. fontSize: 14,
  97. color: Color(0XFFF2F2F2),
  98. ),
  99. headerTextStyle: const TextStyle(
  100. fontSize: 14,
  101. color: Colors.black,
  102. ),
  103. ),
  104. );
  105. }
  106. static String formatTime(int hour, int minute) {
  107. String formattedHour = hour < 10 ? '0$hour' : '$hour';
  108. String formattedMinute = minute < 10 ? '0$minute' : '$minute';
  109. return '$formattedHour:$formattedMinute';
  110. }
  111. }