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.

98 lines
2.6 KiB

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) {
  58. return ThemeData(
  59. fontFamily: 'Vazir',
  60. scaffoldBackgroundColor: const Color(0xffE7E7F5),
  61. useMaterial3: true,
  62. );
  63. }
  64. EdgeInsets allMargin(num? num) {
  65. return EdgeInsets.all(
  66. (num ?? 0).w,
  67. );
  68. }
  69. EdgeInsets singleMargin({num? top, num? right, num? bottom, num? left}) {
  70. return EdgeInsets.only(
  71. top: (top ?? 0).h,
  72. right: (right ?? 0).w,
  73. bottom: (bottom ?? 0).h,
  74. left: (left ?? 0).w,
  75. );
  76. }
  77. EdgeInsets symmetricMargin({horizontal, vertical}) {
  78. return EdgeInsets.symmetric(
  79. horizontal: (horizontal ?? 0).w,
  80. vertical: (vertical ?? 0).w,
  81. );
  82. }
  83. String dateToString(int dateInMilliseconds) {
  84. Jalali jalali = Jalali.fromDateTime(DateTime.fromMillisecondsSinceEpoch(dateInMilliseconds));
  85. return '${jalali.year}/${jalali.month}/${jalali.day}';
  86. }
  87. }