From 50b0d0264cf032b60ebe80f647577f5710c969ab Mon Sep 17 00:00:00 2001 From: Daichi Aoki Date: Sat, 21 Oct 2023 20:38:42 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:books:=20firebase=5Foptions=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=94=E3=83=9A=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/outline/chapter5.md | 64 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/docs/outline/chapter5.md b/docs/outline/chapter5.md index cc444c2..f640b7e 100644 --- a/docs/outline/chapter5.md +++ b/docs/outline/chapter5.md @@ -5,7 +5,67 @@ flutter pub add firebase_core flutter pub add cloud_firestore ``` -[GitHub Discussions](https://github.com/FlutterKaigi/tic_tac_toe_handson/discussions) から `firebase-options.dart` を取得し、Libに追加します。 +`firebase_options.dart` をLibに追加します。 + +```dart +// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' + show defaultTargetPlatform, kIsWeb, TargetPlatform; + +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for web - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return android; + case TargetPlatform.iOS: + return ios; + case TargetPlatform.macOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for macos - ' + '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.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions android = FirebaseOptions( + apiKey: 'AIzaSyCCWnRieFsedimIvgsjNevAdUSb0dm1faY', + appId: '1:807943088200:android:d989c8a1b020562321907d', + messagingSenderId: '807943088200', + projectId: 'tic-tac-toe-handson', + storageBucket: 'tic-tac-toe-handson.appspot.com', + ); + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyBZHELrAr4SRfXLYrxc4zF27P0R3sGsbi0', + appId: '1:807943088200:ios:125d7bfaa751582d21907d', + messagingSenderId: '807943088200', + projectId: 'tic-tac-toe-handson', + storageBucket: 'tic-tac-toe-handson.appspot.com', + iosBundleId: 'com.example.ticTacToeHandson', + ); +} +``` 次に `main.dart` を修正します。 ```dart @@ -40,7 +100,7 @@ classpath 'com.google.gms:google-services:4.3.10' ``` ### 2. iOSでのビルド準備を進める -iOSフォルダをXcodeで開いたのちに、Runnerに`google-services.json` を追加します。 +iOSフォルダをXcodeで開いたのちに、Runnerに[GitHub Discussions](https://github.com/FlutterKaigi/tic_tac_toe_handson/discussions) で取得した `GoogleService-Info.plist` を追加します。 このとき、「Copy items if needed」にチェックを入れて追加してください。 ![Alt text](../public/chapter5/add_plist.png) From e1128e14808c7acc336190278b5ea074f72cbc9e Mon Sep 17 00:00:00 2001 From: Daichi Aoki Date: Sat, 21 Oct 2023 20:41:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:books:=20iOS,Android=E4=BB=A5=E5=A4=96?= =?UTF-8?q?=E3=82=92default=E3=81=A7=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/outline/chapter5.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/docs/outline/chapter5.md b/docs/outline/chapter5.md index f640b7e..c891546 100644 --- a/docs/outline/chapter5.md +++ b/docs/outline/chapter5.md @@ -26,21 +26,6 @@ class DefaultFirebaseOptions { return android; case TargetPlatform.iOS: return ios; - case TargetPlatform.macOS: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for macos - ' - '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.', - ); - case TargetPlatform.linux: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for linux - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); default: throw UnsupportedError( 'DefaultFirebaseOptions are not supported for this platform.',