|
- import 'package:flutter/material.dart';
- import 'package:flutter_persian_calendar/flutter_persian_calendar.dart';
- import 'package:qadirneyriz/config/config.dart';
- import 'package:shamsi_date/shamsi_date.dart';
-
- class Tools {
- static String combineErrorMessages(Map<dynamic, dynamic> errorJson) {
- final combinedMessages = <String>[];
-
- errorJson.forEach((key, value) {
- if (value is List) {
- combinedMessages.addAll(value.cast<String>());
- }
- });
-
- return combinedMessages.join('\n');
- }
-
- static void showCustomSnackBar(BuildContext context,
- {bool? isError, bool isDefault = true, required String text}) {
- Color backgroundColor;
-
- if (isError == true) {
- backgroundColor = Colors.redAccent;
- } else if (isError == false) {
- backgroundColor = Colors.green;
- } else {
- backgroundColor = Colors.blueAccent;
- }
-
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(
- text, // متن بر اساس وضعیت خطا تغییر میکند
- style: const TextStyle(
- fontSize: 12,
- color: Colors.white, // رنگ متن
- fontWeight: FontWeight.normal, // ضخامت متن
- ),
- ),
- backgroundColor: backgroundColor, // رنگ پسزمینه بر اساس وضعیت خطا
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(5), // گرد کردن لبهها
- ),
- behavior: SnackBarBehavior.floating, // تغییر مکان نمایش به حالت شناور
- margin: const EdgeInsets.all(16), // فاصله از لبههای صفحه
- // action: SnackBarAction(
- // label: 'UNDO',
- // textColor: Colors.yellow, // رنگ متن اکشن
- // onPressed: () {},
- // ),
- ),
- );
- }
-
- static String getMonthName(int month) {
- const months = [
- 'فروردین',
- 'اردیبهشت',
- 'خرداد',
- 'تیر',
- 'مرداد',
- 'شهریور',
- 'مهر',
- 'آبان',
- 'آذر',
- 'دی',
- 'بهمن',
- 'اسفند'
- ];
- return months[month - 1];
- }
-
- static PersianCalendar shamsiDateCalendarWidget(
- BuildContext context,
- Function(Jalali) onDateSelected,
- ) {
- return PersianCalendar(
- calendarHeight: 376,
- calendarWidth: 360,
- selectedDate: Jalali.now(),
- onDateChanged: (newDate) {
- onDateSelected(newDate); // Call the function passed to update the date
- },
- onConfirmButtonPressed: () {
- Navigator.pop(
- context); // Pop widget when user presses on confirm button
- },
- calendarStartDate: Jalali(1400, 1, 1),
- calendarEndDate: Jalali(1450, 1, 1),
- calendarTheme: PersianCalendarTheme(
- backgroundColor: const Color(0XFFEDF2F4),
- selectedColor: config.ui.mainGreen,
- headerBackgroundColor: const Color(0XFF8D99AE),
- textStyle: const TextStyle(
- fontSize: 14,
- color: Colors.black,
- ),
- selectedItemTextStyle: const TextStyle(
- fontSize: 14,
- color: Color(0XFFF2F2F2),
- ),
- confirmButtonTextStyle: const TextStyle(
- fontSize: 14,
- color: Color(0XFFF2F2F2),
- ),
- headerTextStyle: const TextStyle(
- fontSize: 14,
- color: Colors.black,
- ),
- ),
- );
- }
-
- static String formatTime(int hour, int minute) {
- String formattedHour = hour < 10 ? '0$hour' : '$hour';
- String formattedMinute = minute < 10 ? '0$minute' : '$minute';
- return '$formattedHour:$formattedMinute';
- }
- }
|