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.

134 lines
3.7 KiB

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