2023-05-23 15:36:55 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:developer';
|
2022-09-19 17:31:42 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-02-01 16:08:30 +00:00
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
2022-09-21 21:59:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-09-19 17:31:42 +00:00
|
|
|
abstract class Util {
|
2022-10-20 17:36:49 +00:00
|
|
|
static Directory? libraryPath;
|
2022-11-28 18:46:35 +00:00
|
|
|
static double? screenWidth;
|
|
|
|
|
2022-09-19 17:31:42 +00:00
|
|
|
static bool get isDesktop {
|
2022-11-28 18:46:35 +00:00
|
|
|
// special check for running on linux based phones
|
|
|
|
if (Platform.isLinux && screenWidth != null && screenWidth! < 800) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// special check for running under ipad mode in macos
|
|
|
|
if (Platform.isIOS &&
|
|
|
|
libraryPath != null &&
|
|
|
|
!libraryPath!.path.contains("/var/mobile/")) {
|
2022-10-20 17:36:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-11-28 18:46:35 +00:00
|
|
|
|
2022-09-19 17:31:42 +00:00
|
|
|
return Platform.isLinux || Platform.isMacOS || Platform.isWindows;
|
|
|
|
}
|
2022-09-21 21:59:52 +00:00
|
|
|
|
2023-02-01 16:08:30 +00:00
|
|
|
static Future<bool> get isIPad async {
|
|
|
|
final deviceInfo = (await DeviceInfoPlugin().deviceInfo);
|
|
|
|
if (deviceInfo is IosDeviceInfo) {
|
|
|
|
return (deviceInfo).name?.toLowerCase().contains("ipad") == true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-21 21:59:52 +00:00
|
|
|
static MaterialColor createMaterialColor(Color color) {
|
|
|
|
List<double> strengths = <double>[.05];
|
|
|
|
final swatch = <int, Color>{};
|
|
|
|
final int r = color.red, g = color.green, b = color.blue;
|
|
|
|
|
|
|
|
for (int i = 1; i < 10; i++) {
|
|
|
|
strengths.add(0.1 * i);
|
|
|
|
}
|
|
|
|
for (var strength in strengths) {
|
|
|
|
final double ds = 0.5 - strength;
|
|
|
|
swatch[(strength * 1000).round()] = Color.fromRGBO(
|
|
|
|
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
|
|
|
|
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
|
|
|
|
b + ((ds < 0 ? b : (255 - b)) * ds).round(),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return MaterialColor(color.value, swatch);
|
|
|
|
}
|
2023-05-23 15:36:55 +00:00
|
|
|
|
|
|
|
static void printJson(dynamic json) {
|
|
|
|
if (json is Map || json is List) {
|
|
|
|
final spaces = ' ' * 4;
|
|
|
|
final encoder = JsonEncoder.withIndent(spaces);
|
|
|
|
final pretty = encoder.convert(json);
|
|
|
|
log(pretty);
|
|
|
|
} else {
|
|
|
|
log(dynamic.toString());
|
|
|
|
}
|
|
|
|
}
|
2022-09-19 17:31:42 +00:00
|
|
|
}
|