Skip to content

Commit

Permalink
remove dart:io for support web (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
melodysdreamj authored May 8, 2024
1 parent 6bafe6f commit 987c462
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions lib/src/screen_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* email: zhuoyuan93@gmail.com
*/

import 'dart:io';
import 'package:flutter/foundation.dart' show kIsWeb, defaultTargetPlatform;

import 'dart:math' show min, max;
import 'dart:ui' as ui show FlutterView;

Expand Down Expand Up @@ -241,34 +242,40 @@ class ScreenUtil {
double setSp(num fontSize) =>
fontSizeResolver?.call(fontSize, _instance) ?? fontSize * scaleText;

DeviceType deviceType() {
DeviceType deviceType;
switch (Platform.operatingSystem) {
case 'android':
case 'ios':
deviceType = DeviceType.mobile;
if ((orientation == Orientation.portrait && screenWidth < 600) ||
(orientation == Orientation.landscape && screenHeight < 600)) {
deviceType = DeviceType.mobile;
} else {
deviceType = DeviceType.tablet;
DeviceType deviceType(BuildContext context) {
var deviceType = DeviceType.web;
final screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height;
final orientation = MediaQuery.of(context).orientation;

if (kIsWeb) {
deviceType = DeviceType.web;
} else {
bool isMobile = defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.android;
bool isTablet = (orientation == Orientation.portrait && screenWidth >= 600) || (orientation == Orientation.landscape && screenHeight >= 600);

if (isMobile) {
deviceType = isTablet ? DeviceType.tablet : DeviceType.mobile;
} else {
switch (defaultTargetPlatform) {
case TargetPlatform.linux:
deviceType = DeviceType.linux;
break;
case TargetPlatform.macOS:
deviceType = DeviceType.mac;
break;
case TargetPlatform.windows:
deviceType = DeviceType.windows;
break;
case TargetPlatform.fuchsia:
deviceType = DeviceType.fuchsia;
break;
default:
break;
}
break;
case 'linux':
deviceType = DeviceType.linux;
break;
case 'macos':
deviceType = DeviceType.mac;
break;
case 'windows':
deviceType = DeviceType.windows;
break;
case 'fuchsia':
deviceType = DeviceType.fuchsia;
break;
default:
deviceType = DeviceType.web;
}
}

return deviceType;
}

Expand Down

0 comments on commit 987c462

Please sign in to comment.