byType<T> method
T
byType<T>({
- required T defaultValue,
- T? web,
- T? desktop,
- T? mobile,
byType Method Documentation :
Returns a value based on the current platform type.
defaultValue
: The default value to return if the current platform type does not match any provided case.web
: The value to return if the current platform type is web.desktop
: The value to return if the current platform type is desktop.mobile
: The value to return if the current platform type is mobile.
Example:
var result = platform.byType<String>(
defaultValue: 'Unknown Type',
web: 'Web Platform',
desktop: 'Desktop Platform',
mobile: 'Mobile Platform',
);
Implementation
T byType<T>({required T defaultValue, T? web, T? desktop, T? mobile}) {
return switch (this.type) {
PlatformType.web => web ??= defaultValue,
PlatformType.desktop => desktop ??= defaultValue,
PlatformType.mobile => mobile ??= defaultValue,
};
}