byName<T> method
T
byName<T>({
- required T defaultValue,
- T? android,
- T? webAndroid,
- T? iOS,
- T? webIOS,
- T? macOs,
- T? webMacOs,
- T? windows,
- T? webWindows,
- T? linux,
- T? webLinux,
byName Method Documentation :
Returns a value based on the current platform name.
defaultValue
: The default value to return if the current platform name does not match any provided case.android
: The value to return if the current platform name is Android.webAndroid
: The value to return if the current platform name is Web Android.iOS
: The value to return if the current platform name is iOS.webIOS
: The value to return if the current platform name is Web iOS.macOs
: The value to return if the current platform name is macOS.webMacOs
: The value to return if the current platform name is Web macOS.windows
: The value to return if the current platform name is Windows.webWindows
: The value to return if the current platform name is Web Windows.linux
: The value to return if the current platform name is Linux.webLinux
: The value to return if the current platform name is Web Linux.
Example:
var result = platform.byName<String>(
defaultValue: 'Unknown Platform',
android: 'Android Platform',
webAndroid: 'Web on Android Platform',
iOS: 'iOS Platform',
webIOS: 'Web on iOS Platform',
macOs: 'macOS Platform',
webMacOs: 'Web on macOS Platform',
windows: 'Windows Platform',
webWindows: 'Web on Windows Platform',
linux: 'Linux Platform',
webLinux: 'Web on Linux Platform',
);
Implementation
T byName<T>(
{required T defaultValue,
T? android,
T? webAndroid,
T? iOS,
T? webIOS,
T? macOs,
T? webMacOs,
T? windows,
T? webWindows,
T? linux,
T? webLinux}) {
return switch (this.name) {
PlatformName.android => android ??= defaultValue,
PlatformName.web_android => webAndroid ??= defaultValue,
PlatformName.iOS => iOS ??= defaultValue,
PlatformName.web_iOS => webIOS ??= defaultValue,
PlatformName.macOs => macOs ??= defaultValue,
PlatformName.web_macOs => webMacOs ??= defaultValue,
PlatformName.windows => windows ??= defaultValue,
PlatformName.web_windows => webWindows ??= defaultValue,
PlatformName.linux => linux ??= defaultValue,
PlatformName.web_linux => webLinux ??= defaultValue,
};
}