masalibの日記

システム開発、運用と猫の写真ブログです

FlutterFire CLIで作成したfirebase_options.dartがおかしい件

qiita.com

を参考に環境構築をしてflutterfire configureして問題なく作成された が

実際に動かしてみると

Error (Xcode): lib/firebase_options.dart:26:13: Error: The type 'TargetPlatform' is not exhaustively matched by the switch cases since it doesn't match 'TargetPlatform.fuchsia'.

とエラーが発生する・・・ chatgptで調べてみると

エラーは、TargetPlatformのswitch文でTargetPlatform.fuchsiaを扱っていないために発生しています。 解決策は以下ですと記載されていた

switch (defaultTargetPlatform) {
  case TargetPlatform.android:
    // Android用のコード
    break;
  case TargetPlatform.iOS:
    // iOS用のコード
    break;
  case TargetPlatform.macOS:
    // macOS用のコード
    break;
  case TargetPlatform.windows:
    // Windows用のコード
    break;
  case TargetPlatform.linux:
    // Linux用のコード
    break;
  case TargetPlatform.fuchsia:
    // Fuchsia用のコード
    break;
  default:
    // その他のプラットフォーム用のコード(必要ならば)
    break;
}

がうまくいかず

色々試してみた結果、以下のコードになった

    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
        return android;
      case TargetPlatform.iOS:
        return ios;
      case TargetPlatform.fuchsia:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for macos - '
              'you can reconfigure this by running the FlutterFire CLI again.',
        );
      case TargetPlatform.macOS:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for macos - '
              'you can reconfigure this by running the FlutterFire CLI again.',
        );
      case TargetPlatform.linux:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for linux - '
              'you can reconfigure this by running the FlutterFire CLI again.',
        );
      case TargetPlatform.windows:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for windows - '
              'you can reconfigure this by running the FlutterFire CLI again.',
        );
    }

公式が間違えているとかやめてほしい