byCompany<T> method

T byCompany<T>({
  1. required T defaultValue,
  2. T? apple,
  3. T? google,
  4. T? linux,
  5. T? microsoft,
})

byCompany Method Documentation :

Returns a value based on the current platform company.

  • defaultValue : The default value to return if the current platform company does not match any provided case.
  • apple : The value to return if the current platform company is Apple.
  • google : The value to return if the current platform company is Google.
  • microsoft : The value to return if the current platform company is Microsoft.
  • linux : The value to return if the current platform company is Linux.

Example:

var result = platform.byCompany<String>(
  defaultValue: 'Unknown Company',
  apple: 'Apple Inc.',
  google: 'Google Inc.',
  microsoft: 'Microsoft Corporation',
  linux: 'Linux OS',
);

Implementation

T byCompany<T>(
    {required T defaultValue, T? apple, T? google, T? linux, T? microsoft}) {
  return switch (this.company) {
    PlatformCompany.apple => apple ??= defaultValue,
    PlatformCompany.google => google ??= defaultValue,
    PlatformCompany.microsoft => microsoft ??= defaultValue,
    PlatformCompany.linux => linux ??= defaultValue,
  };
}