Sonnat Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.2 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:shamsi_date/shamsi_date.dart';
  4. import 'package:sonnat/core/extensions/number_extension.dart';
  5. import 'package:sonnat/core/utils/toast.dart';
  6. class DisableScrollEffect extends ScrollBehavior {
  7. @override
  8. Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
  9. return child;
  10. }
  11. }
  12. class Utils {
  13. Utils.privateConstructor();
  14. static final Utils instance = Utils.privateConstructor();
  15. factory Utils() {
  16. return instance;
  17. }
  18. void showToast(BuildContext? context, String? txt, {bool isError = true, ToastGravity gravity = ToastGravity.top}) {
  19. try {
  20. if (context == null) return;
  21. if (txt == null || txt.isEmpty) {
  22. if (isError == false) {
  23. return;
  24. }
  25. txt = 'خطا در برقراری ارتباط';
  26. }
  27. FToast fToast = FToast();
  28. fToast.init(context);
  29. Widget toast = Container(
  30. padding: const EdgeInsetsDirectional.all(16),
  31. decoration: BoxDecoration(
  32. borderRadius: BorderRadius.circular(8),
  33. color: isError ? Colors.red : Colors.lightBlue,
  34. ),
  35. child: Text(
  36. txt,
  37. style: const TextStyle(
  38. color: Colors.white,
  39. fontWeight: FontWeight.bold,
  40. ),
  41. ),
  42. );
  43. fToast.showToast(child: toast, gravity: gravity, toastDuration: const Duration(milliseconds: 1500));
  44. } catch (e) {
  45. assert(() {
  46. if (kDebugMode) {
  47. print(e);
  48. }
  49. return true;
  50. }());
  51. }
  52. }
  53. String showTimeInJalali(DateTime dateTime) {
  54. Jalali jalali = Jalali.fromDateTime(dateTime);
  55. return '${jalali.year}/${jalali.month}/${jalali.day}';
  56. }
  57. ThemeData getAppTheme(BuildContext context, String language) {
  58. switch (language) {
  59. case 'fa':
  60. return ThemeData(
  61. fontFamily: 'Vazir',
  62. scaffoldBackgroundColor: const Color(0xffE7E7F5),
  63. useMaterial3: true,
  64. );
  65. case 'en':
  66. return ThemeData(
  67. fontFamily: 'Cairo',
  68. scaffoldBackgroundColor: const Color(0xffE7E7F5),
  69. useMaterial3: true,
  70. );
  71. case 'ar':
  72. return ThemeData(
  73. fontFamily: 'Vazir',
  74. scaffoldBackgroundColor: const Color(0xffE7E7F5),
  75. useMaterial3: true,
  76. );
  77. }
  78. return ThemeData(
  79. fontFamily: 'Vazir',
  80. scaffoldBackgroundColor: const Color(0xffE7E7F5),
  81. useMaterial3: true,
  82. );
  83. }
  84. EdgeInsets allMargin(num? num) {
  85. return EdgeInsets.all(
  86. (num ?? 0).w,
  87. );
  88. }
  89. EdgeInsets singleMargin({num? top, num? right, num? bottom, num? left}) {
  90. return EdgeInsets.only(
  91. top: (top ?? 0).h,
  92. right: (right ?? 0).w,
  93. bottom: (bottom ?? 0).h,
  94. left: (left ?? 0).w,
  95. );
  96. }
  97. EdgeInsets symmetricMargin({horizontal, vertical}) {
  98. return EdgeInsets.symmetric(
  99. horizontal: (horizontal ?? 0).w,
  100. vertical: (vertical ?? 0).w,
  101. );
  102. }
  103. String dateToString(int dateInMilliseconds) {
  104. Jalali jalali = Jalali.fromDateTime(DateTime.fromMillisecondsSinceEpoch(dateInMilliseconds));
  105. return '${jalali.year}/${jalali.month}/${jalali.day}';
  106. }
  107. }