Flutterでアプリを作ってみる
Flutterでアプリを作る
RNで作ってきたから慣れてるけど、あえての挑戦。
気になる点(RN(Expo)ならできるけど、Flutterは???)
- CIでビルドできるのか
- ビルド後にストアにアップロードまでいけるのか?(行けなくてもいいけど、できたら楽)
公式サイトここ
ドキュメントはここ
Flutterをインストールする
公式の方法もあるけど
brewでインストールできそうなのでそっちでやる
$ brew install flutter
🍺 flutter was successfully installed!問題なくいけそう
vscodeで開発するための情報もあった
おそらくこいつを入れろってこと
firebaseと繋いでみる
swift package managerが必要みたい
Xcode 13.2.1
Swift Package Managerがない...!!!
Firebaseのとこに書いてあるやり方じゃできなかった



これ追加してってかいてあった。
import UIKit
import Flutter
+ import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
+ FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
下記で紹介されてたから、追加
とおもったら、使えないのでFirebase.apps.isEmptyで判定をする
import UIKit
import Flutter
import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
+ if (Firebase.apps.isEmpty) {
FirebaseApp.configure()
+ }
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
エラー発生
Error running pod install
swift package managerはつかえなさそう
# Uncomment this line to define a global platform for your project
- # platform :ios, '9.0'
+ platform :ios, '10.6'
...
+ pod 'Firebase/Analytics'
+ pod 'Firebase/Auth'
+ pod 'Firebase/Firestore'
すなおにpodinstall
FlutterにFireBase入れられた
結局初期化してから、flutterfire configureをつかった
動作確認してみる
これでうまくいった
デバッグモード(iOSのシュミレーターや実機)でGoogleのsign inをすると、アプリがクラッシュする問題の解決方法は
下記をinfo.plistに追記するだけ
<?xml version="1.0" encoding="UTF-8"?>
...
<dict>
...
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>{GoogleService-Info.plist の REVERSED_CLIENT_IDを入れる}</string>
</array>
</dict>
</array>
...
</dict>
</plist>
cocoapodsはbrewでinstallできる
routesで管理してみた。
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Firebase.apps.isEmpty) {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
}
runApp(const App());
}
Widget build(BuildContext context) {
return MaterialApp(
...
initialRoute:
FirebaseAuth.instance.currentUser == null ? '/sign-in' : '/',
routes: {
'/sign-in': (context) => SignInScreen(
actions: [
AuthStateChangeAction<SignedIn>((context, _) {
Navigator.of(context).pushReplacementNamed('/');
}),
],
providerConfigs: providerConfigs,
),
'/': (context) => const Tabs()
},
...
}
これだと、下記エラーが発生する。
initializeAppを2回するなってエラー
FirebaseException ([core/duplicate-app] A Firebase App named "[DEFAULT]" already exists)
だいたい掴めているのは、ログイン後に発生している。
Firebase.apps.isEmptyはtrueである
全然関係なかった
nameつけたら解決
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Firebase.apps.isEmpty) {
await Firebase.initializeApp(
name: 'Hoge',
options: DefaultFirebaseOptions.currentPlatform,
);
}
runApp(const App());
}
実機確認してみる
flutter runでの確認ではなく、ちゃんとインストールして確認
flutter build ios
デバイスの確認
flutter devices
対象のデバイスにインストール
flutter install -d [ここ頭文字]
アプリのアイコン設定
flutter_launcher_icons を使用
✓ Successfully generated launcher icons
Unhandled exception:
FormatException: Invalid number (at character 1)
^
#0 int._handleFormatError (dart:core-patch/integers_patch.dart:129:7)
...
こんなエラーが出たから、下記に書き直してrunしたら動いた
flutter_launcher_icons:
git:
url: https://github.com/Davenchy/flutter_launcher_icons.git
ref: fixMinSdkParseFlutter2.8
════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v0.9.1)
════════════════════════════════════════════
• Creating default icons Android
• Adding a new Android launcher icon
• Overwriting default iOS launcher icon with new icon
✓ Successfully generated launcher icons
リリース準備に取り掛かってる
flutter clean と flutter build ios をする
XcodeでArchiveをする
終わったらDistribute Appを実行
App申請の時に電話番号でエラーが出たら
080の0をとった80から入力するか
+81をつけるといける
プライバシーポリシーのページが必要みたいだから、githubpagesで作る
無事に、審査出したのでクローズ
リジェクトされた!!!!
Guideline 5.1.1 - Legal - Privacy - Data Collection and Storage
We noticed that your app requires users to register or log in to access features that are not account based.
Apps may not require users to enter personal information to function, except when directly relevant to the core functionality of the app or required by law. For example, an e-commerce app should let users browse store offerings and other features that are not account based before being asked to register, or a restaurant app should allow users to explore the menu before placing an order. Registration must then only be required for account-specific features, such as saving items for future reference or placing an order.
Next Steps
To resolve this issue, please revise your app to let users freely access your app’s features that are not account based.
Resources
See guideline 5.1.1(v) - Account Sign-In to learn more about our requirements for apps with account-based content and features.
おそらく、必要な理由をつければいけそうだけど、
Firebaseの匿名ログインで対応する。
匿名ログイン後、アカウント紐付けができなければ却下
await FirebaseAuth.instance.signInAnonymously();
Firebaseのログイン プロバイダで匿名を選択する必要がある
FirebaseAuthException ([firebase_auth/admin-restricted-operation] ADMIN_ONLY_OPERATION)