import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:shamsi_date/shamsi_date.dart'; import 'package:sonnat/core/extensions/number_extension.dart'; import 'package:sonnat/core/language/language_cubit.dart'; import 'package:sonnat/core/utils/toast.dart'; class DisableScrollEffect extends ScrollBehavior { @override Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { return child; } } class Utils { Utils.privateConstructor(); static final Utils instance = Utils.privateConstructor(); factory Utils() { return instance; } void showToast(BuildContext? context, String? txt, {bool isError = true, ToastGravity gravity = ToastGravity.top}) { try { if (context == null) return; if (txt == null || txt.isEmpty) { if (isError == false) { return; } txt = 'خطا در برقراری ارتباط'; } FToast fToast = FToast(); fToast.init(context); Widget toast = Container( padding: const EdgeInsetsDirectional.all(16), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), color: isError ? Colors.red : Colors.lightBlue, ), child: Text( txt, style: const TextStyle( color: Colors.white, fontWeight: FontWeight.bold, ), ), ); fToast.showToast(child: toast, gravity: gravity, toastDuration: const Duration(milliseconds: 1500)); } catch (e) { assert(() { if (kDebugMode) { print(e); } return true; }()); } } String showTimeInJalali(DateTime dateTime) { Jalali jalali = Jalali.fromDateTime(dateTime); return '${jalali.year}/${jalali.month}/${jalali.day}'; } ThemeData getAppTheme(BuildContext context, CurrentLanguage language) { switch (language) { case CurrentLanguage.en: return ThemeData( scaffoldBackgroundColor: const Color(0xffE7E7F5), useMaterial3: true, ); case CurrentLanguage.fa: return ThemeData( fontFamily: 'Vazir', scaffoldBackgroundColor: const Color(0xffE7E7F5), useMaterial3: true, ); case CurrentLanguage.ar: return ThemeData( fontFamily: 'Cairo', useMaterial3: true, scaffoldBackgroundColor: const Color(0xffE7E7F5), ); } } EdgeInsets allMargin(num? num) { return EdgeInsets.all( (num ?? 0).w, ); } EdgeInsets singleMargin({num? top, num? right, num? bottom, num? left}) { return EdgeInsets.only( top: (top ?? 0).h, right: (right ?? 0).w, bottom: (bottom ?? 0).h, left: (left ?? 0).w, ); } EdgeInsets symmetricMargin({horizontal, vertical}) { return EdgeInsets.symmetric( horizontal: (horizontal ?? 0).w, vertical: (vertical ?? 0).w, ); } }