Skip to content

feat(firebase-ai-logic-basics): update Flutter SDK setup and add App Check guide - #221

Open
AustinBenoit wants to merge 1 commit into
ai-logic/2b-setup-iosfrom
ai-logic/2c-setup-flutter
Open

AustinBenoit wants to merge 1 commit into
ai-logic/2b-setup-iosfrom
ai-logic/2c-setup-flutter

Conversation

@AustinBenoit

@AustinBenoit AustinBenoit commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Updates references/sdk/setup/flutter_setup.md for firebase_ai v4.0.0+ (FirebaseAI.googleAI(useLimitedUseAppCheckTokens: true) / FirebaseAI.agentPlatform()) and adds full Flutter App Check setup (providerAndroid, providerApple, providerWeb, and --dart-define CI debug tokens).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Firebase AI Logic Flutter Setup Guide to reflect the renamed SDK, update installation and initialization instructions, and add detailed guidance on App Check integration, replay protection, and debug providers. The review feedback highlights several critical API mismatches in the provided Dart code examples: Firebase.initializeApp() should include DefaultFirebaseOptions.currentPlatform for cross-platform compatibility, and the FirebaseAppCheck.activate() configuration needs to be corrected to use the actual androidProvider, appleProvider, and webProvider parameters with their corresponding enums instead of non-existent provider classes.

Comment on lines 51 to 59
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'package:flutter/material.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAuth.instance.signInAnonymously();
runApp(const MyApp());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To align with the CLI-first approach and the note above about using flutterfire configure strictly for generating firebase_options.dart, we should import firebase_options.dart and pass options: DefaultFirebaseOptions.currentPlatform to Firebase.initializeApp(). Otherwise, initialization will fail on platforms like Web or if native configuration files are not manually integrated.

Suggested change
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAuth.instance.signInAnonymously();
runApp(const MyApp());
}
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}

Comment on lines +115 to +132
import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate(
// Android: Play Integrity (production) or AndroidDebugProvider() (development)
providerAndroid: const AndroidPlayIntegrityProvider(),
// iOS/macOS: AppleAppAttestProvider(), AppleDeviceCheckProvider(),
// AppleAppAttestWithDeviceCheckFallbackProvider(), or AppleDebugProvider() (development)
providerApple: const AppleAppAttestProvider(),
// Web: reCAPTCHA Enterprise (recommended) or ReCaptchaV3Provider
providerWeb: ReCaptchaEnterpriseProvider('recaptcha-enterprise-site-key'),
);
runApp(const MyApp());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Flutter's firebase_app_check package, the parameters for activate() are androidProvider, appleProvider, and webProvider (not providerAndroid, providerApple, providerWeb). Additionally, for Android and iOS, the method expects AndroidProvider and AppleProvider enums rather than class instances like AndroidPlayIntegrityProvider or AppleAppAttestProvider. Also, we should pass options: DefaultFirebaseOptions.currentPlatform to Firebase.initializeApp() here as well.

Suggested change
import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate(
// Android: Play Integrity (production) or AndroidDebugProvider() (development)
providerAndroid: const AndroidPlayIntegrityProvider(),
// iOS/macOS: AppleAppAttestProvider(), AppleDeviceCheckProvider(),
// AppleAppAttestWithDeviceCheckFallbackProvider(), or AppleDebugProvider() (development)
providerApple: const AppleAppAttestProvider(),
// Web: reCAPTCHA Enterprise (recommended) or ReCaptchaV3Provider
providerWeb: ReCaptchaEnterpriseProvider('recaptcha-enterprise-site-key'),
);
runApp(const MyApp());
}
import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
await FirebaseAppCheck.instance.activate(
// Android: Play Integrity (production) or AndroidProvider.debug (development)
androidProvider: AndroidProvider.playIntegrity,
// iOS/macOS: AppleProvider.appAttest, AppleProvider.deviceCheck, or AppleProvider.debug (development)
appleProvider: AppleProvider.appAttest,
// Web: reCAPTCHA Enterprise (recommended) or ReCaptchaV3Provider
webProvider: ReCaptchaEnterpriseProvider('recaptcha-enterprise-site-key'),
);
runApp(const MyApp());
}

Comment on lines +191 to +201
await FirebaseAppCheck.instance.activate(
providerAndroid: kDebugMode
? AndroidDebugProvider(debugToken: stableDebugToken)
: const AndroidPlayIntegrityProvider(),
providerApple: kDebugMode
? AppleDebugProvider(debugToken: stableDebugToken)
: const AppleAppAttestProvider(),
providerWeb: kDebugMode
? WebDebugProvider(debugToken: stableDebugToken)
: ReCaptchaEnterpriseProvider('recaptcha-enterprise-site-key'),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Flutter's firebase_app_check package, there are no AndroidDebugProvider, AppleDebugProvider, or WebDebugProvider classes that accept a debugToken parameter in Dart. Instead, use the AndroidProvider.debug and AppleProvider.debug enums, and WebDebugProvider() for Web. The debug token itself is printed to the console/logs on first run or configured via native environment variables/build setups, rather than passed programmatically in Dart.

Suggested change
await FirebaseAppCheck.instance.activate(
providerAndroid: kDebugMode
? AndroidDebugProvider(debugToken: stableDebugToken)
: const AndroidPlayIntegrityProvider(),
providerApple: kDebugMode
? AppleDebugProvider(debugToken: stableDebugToken)
: const AppleAppAttestProvider(),
providerWeb: kDebugMode
? WebDebugProvider(debugToken: stableDebugToken)
: ReCaptchaEnterpriseProvider('recaptcha-enterprise-site-key'),
);
await FirebaseAppCheck.instance.activate(
androidProvider: kDebugMode
? AndroidProvider.debug
: AndroidProvider.playIntegrity,
appleProvider: kDebugMode
? AppleProvider.debug
: AppleProvider.appAttest,
webProvider: kDebugMode
? WebDebugProvider()
: ReCaptchaEnterpriseProvider('recaptcha-enterprise-site-key'),
);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant