-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add platform detection * update CatalystPlatform for web * update CatalystPlatform
- Loading branch information
Showing
9 changed files
with
131 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
4 changes: 1 addition & 3 deletions
4
catalyst_voices/packages/catalyst_voices_shared/lib/src/catalyst_voices_shared.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
class CatalystVoicesShared { | ||
const CatalystVoicesShared(); | ||
} | ||
export 'platform/catalyst_platform.dart'; |
5 changes: 5 additions & 0 deletions
5
catalyst_voices/packages/catalyst_voices_shared/lib/src/platform/catalyst_platform.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
library catalyst_platform; | ||
|
||
export 'stub_platform.dart' | ||
if (dart.library.io) 'io_platform.dart' | ||
if (dart.library.html) 'web_platform.dart'; |
26 changes: 26 additions & 0 deletions
26
catalyst_voices/packages/catalyst_voices_shared/lib/src/platform/io_platform.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'dart:io'; | ||
|
||
final class CatalystPlatform { | ||
static bool get isAndroid => Platform.isAndroid; | ||
|
||
static bool get isDesktop => | ||
Platform.isLinux || Platform.isMacOS || Platform.isWindows; | ||
|
||
static bool get isFuchsia => Platform.isFuchsia; | ||
|
||
static bool get isIOS => Platform.isIOS; | ||
|
||
static bool get isLinux => Platform.isLinux; | ||
|
||
static bool get isMacOS => Platform.isMacOS; | ||
|
||
static bool get isMobile => Platform.isAndroid || Platform.isIOS; | ||
|
||
static bool get isMobileWeb => false; | ||
|
||
static bool get isWeb => false; | ||
|
||
static bool get isWebDesktop => false; | ||
|
||
static bool get isWindows => Platform.isWindows; | ||
} |
47 changes: 47 additions & 0 deletions
47
catalyst_voices/packages/catalyst_voices_shared/lib/src/platform/stub_platform.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
final class CatalystPlatform { | ||
static bool get isAndroid { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isDesktop { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isFuchsia { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isIOS { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isLinux { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isMacOS { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isMobile { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isMobileWeb { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isWeb { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isWebDesktop { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
static bool get isWindows { | ||
throw UnimplementedError('Stub CatalystPlatform'); | ||
} | ||
|
||
const CatalystPlatform._(); | ||
} |
38 changes: 38 additions & 0 deletions
38
catalyst_voices/packages/catalyst_voices_shared/lib/src/platform/web_platform.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/foundation.dart' show kIsWeb; | ||
import 'package:web/web.dart'; | ||
|
||
final class CatalystPlatform { | ||
static bool get isAndroid => false; | ||
|
||
static bool get isDesktop => false; | ||
|
||
static bool get isFuchsia => false; | ||
|
||
static bool get isIOS => false; | ||
|
||
static bool get isLinux => false; | ||
|
||
static bool get isMacOS => false; | ||
|
||
static bool get isMobile => false; | ||
|
||
static bool get isMobileWeb => _isMobileOS; | ||
|
||
static bool get isWeb => kIsWeb; | ||
|
||
static bool get isWebDesktop => kIsWeb && !_isMobileOS; | ||
|
||
static bool get isWindows => false; | ||
|
||
static bool get _isMobileOS { | ||
final userAgent = window.navigator.userAgent.toLowerCase(); | ||
const mobileIdentifiers = [ | ||
'android', | ||
'ipad', | ||
'iphone', | ||
]; | ||
return mobileIdentifiers.any(userAgent.contains); | ||
} | ||
|
||
const CatalystPlatform._(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ environment: | |
dependencies: | ||
flutter: | ||
sdk: flutter | ||
web: ^0.3.0 | ||
|
||
dev_dependencies: | ||
catalyst_analysis: | ||
|