device_utils.dart 826 B

12345678910111213141516171819202122232425262728293031
  1. import 'dart:io';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/foundation.dart';
  4. class DeviceUtils {
  5. static bool get isDesktop => !isWeb && (isWindows || isLinux || isMacOS);
  6. static bool get isMobile => isAndroid || isIOS;
  7. static bool get isWeb => kIsWeb;
  8. static bool get isWindows => !isWeb && Platform.isWindows;
  9. static bool get isLinux => !isWeb && Platform.isLinux;
  10. static bool get isMacOS => !isWeb && Platform.isMacOS;
  11. static bool get isAndroid => !isWeb && Platform.isAndroid;
  12. static bool get isFuchsia => !isWeb && Platform.isFuchsia;
  13. static bool get isIOS => !isWeb && Platform.isIOS;
  14. static bool isDarkMode(BuildContext context) {
  15. Brightness currentBrightness = MediaQuery.of(context).platformBrightness;
  16. return currentBrightness == Brightness.dark;
  17. }
  18. }