Created
March 20, 2024 17:47
-
-
Save snapsl/e9b8b0e0aaf92eeda15eb87d6e9a26a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
extension MobilePlatform on TargetPlatform { | |
/// Checks if platform is mobile. | |
bool isMobilePlatform() => | |
this == TargetPlatform.android || this == TargetPlatform.iOS; | |
} | |
extension CupertinoPlatform on TargetPlatform { | |
/// Checks if platform is an apple device. | |
bool isCupertinoPlatform() { | |
switch (this) { | |
case TargetPlatform.android: | |
case TargetPlatform.fuchsia: | |
case TargetPlatform.linux: | |
case TargetPlatform.windows: | |
return false; | |
case TargetPlatform.iOS: | |
case TargetPlatform.macOS: | |
return true; | |
} | |
} | |
} | |
extension DektopPlatform on TargetPlatform { | |
/// Checks if platform is Desktop. | |
/// | |
/// Returns true when [TargetPlatform] is a desktop platform and not in browser. | |
bool isDektopPlatform() => | |
!kIsWeb && | |
(this == TargetPlatform.windows || | |
this == TargetPlatform.linux || | |
this == TargetPlatform.macOS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment