Skip to content

Instantly share code, notes, and snippets.

@snapsl
Created March 20, 2024 17:47
Show Gist options
  • Save snapsl/e9b8b0e0aaf92eeda15eb87d6e9a26a7 to your computer and use it in GitHub Desktop.
Save snapsl/e9b8b0e0aaf92eeda15eb87d6e9a26a7 to your computer and use it in GitHub Desktop.
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