https://github.com/roundedinfinity/platform_specific
Dart package that simplifies handling platform-specific operations and callbacks in your Dart/Flutter applications.
https://github.com/roundedinfinity/platform_specific
Last synced: 8 months ago
JSON representation
Dart package that simplifies handling platform-specific operations and callbacks in your Dart/Flutter applications.
- Host: GitHub
- URL: https://github.com/roundedinfinity/platform_specific
- Owner: RoundedInfinity
- License: mit
- Created: 2023-05-29T14:54:26.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-04T01:18:26.000Z (over 2 years ago)
- Last Synced: 2025-05-14T09:51:36.784Z (about 1 year ago)
- Language: Dart
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Platform Specific
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[](https://github.com/felangel/mason)
[![License: MIT][license_badge]][license_link]
Dart package that simplifies handling platform-specific operations and callbacks in your Dart/Flutter applications.
## Features ๐
- Execute platform-specific callback functions based on the detected platform type.
- Define custom platform types to handle specific platforms.
- Supports a wide range of platforms out of the box including web, Windows, Linux, Android, macOS, Fuchsia, and iOS.
## Usage ๐งช
Use the `Platforms.on` method to execute the appropriate callback function based on the platform:
```dart
final myValue = Platforms.on(
{
PlatformTypes.android: () {
return '๐ค';
},
PlatformTypes.windows: () {
return '๐ช';
},
PlatformTypes.oneOf([PlatformTypes.iOS, PlatformTypes.macOS]): () {
return '๐';
}
},
orElse: () {
return 'unknown';
},
);
print(myValue); // Output: ๐ (if running on iOS or macOS), ๐ค (if running on Android), ๐ช (if running on Windows), or 'unknown' (if running on any other platform)
```
### Custom Platform Types
You can create custom platform types by extending the `PlatformType` class and overriding the `isPlatform` method. This allows you to handle additional platforms not covered by the predefined types.
```dart
class MyCustomPlatform extends PlatformType {
const MyCustomPlatform();
@override
bool isPlatform(PlatformType? override) {
// Add your custom platform detection logic here
// Should return true if override == this
...
}
}
```
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license_link]: https://opensource.org/licenses/MIT
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis