Skip to content

Commit 1491eb4

Browse files
authored
add idx files for firebase ai logic showcase (flutter#38)
2 parents 2df82ca + 3d5c8e3 commit 1491eb4

File tree

6 files changed

+193
-4
lines changed

6 files changed

+193
-4
lines changed

firebase_ai_logic_showcase/.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,3 @@ ephemeral/
5252
google-services.json
5353
GoogleService-Info.plist
5454
.firebaserc
55-
firebase.json
56-
57-
# Firebase options file
58-
lib/firebase_options.dart
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# To learn more about how to use Nix to configure your environment
2+
# see: https://firebase.google.com/docs/studio/customize-workspace
3+
{ pkgs, ... }: {
4+
# Which nixpkgs channel to use.
5+
channel = "stable-24.05"; # or "unstable"
6+
# Use https://search.nixos.org/packages to find packages
7+
packages = [
8+
pkgs.jdk21
9+
pkgs.unzip
10+
pkgs.nodejs_22
11+
pkgs.nodePackages.nodemon
12+
];
13+
# Sets environment variables in the workspace
14+
env = {
15+
# Enable AppCheck for additional security for critical endpoints.
16+
# Follow the configuration steps in the README to set up your project.
17+
# ENABLE_APPCHECK = "TRUE";
18+
LOCAL_RECOMMENDATION_SERVICE = "http://127.0.0.1:8084";
19+
GOOGLE_PROJECT = "<project-id>";
20+
CLOUDSDK_CORE_PROJECT = "<project-id>";
21+
TF_VAR_project = "<project-id>";
22+
# Flip to true to help improve Angular
23+
NG_CLI_ANALYTICS = "false";
24+
# Quieter Terraform logs
25+
TF_IN_AUTOMATION = "true";
26+
};
27+
idx = {
28+
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
29+
extensions = [
30+
"hashicorp.terraform"
31+
"ms-vscode.js-debug"
32+
"Dart-Code.flutter"
33+
"Dart-Code.dart-code"
34+
];
35+
workspace = {
36+
# Runs when a workspace is first created with this `dev.nix` file
37+
onCreate = {
38+
npm-install = "flutter pub get";
39+
default.openFiles = [
40+
"README.md"
41+
"lib/main.dart"
42+
];
43+
};
44+
# To run something each time the workspace is (re)started, use the `onStart` hook
45+
};
46+
# Enable previews and customize configuration
47+
previews = {
48+
enable = true;
49+
previews = {
50+
web = {
51+
command = [ "flutter" "run" "--machine" "-d" "web-server" "--web-hostname" "0.0.0.0" "--web-port" "$PORT" ];
52+
manager = "flutter";
53+
};
54+
# android = {
55+
# command = [ "flutter" "run" "--machine" "-d" "android" "-d" "localhost:5555" ];
56+
# manager = "flutter";
57+
# };
58+
};
59+
};
60+
};
61+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"firebase_hosting": {},
3+
"cloud_run_deploy": {
4+
"region": "us-central1",
5+
"sourceFlag": "--source services/cloud-run",
6+
"allowUnauthenticatedInvocationsFlag": "--allow-unauthenticated"
7+
},
8+
"gemini_api": {}
9+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "Flutter app with Firebase AI logic",
3+
"description": "A sample flutter app that demonstrates how to use the Gemini API with Firebase AI Logic",
4+
"categories": [
5+
"AI & ML",
6+
"Web",
7+
"Firebase",
8+
"Flutter",
9+
"Android",
10+
"iOS"
11+
],
12+
"icon_image_url": "https://www.gstatic.com/monospace/240513/logo_firebase.svg",
13+
"publisher": "Google LLC",
14+
"params": [
15+
{
16+
"id": "projectId",
17+
"name": "Firebase Project ID",
18+
"type": "string",
19+
"required": true
20+
},
21+
{
22+
"id": "bootstrapJs",
23+
"name": "Sample App Bootstrap",
24+
"type": "string",
25+
"required": false
26+
}
27+
]
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ pkgs, projectId, bootstrapJs, ... }:
2+
{
3+
bootstrap = ''
4+
cp -rf ${./.} "$out/"
5+
chmod -R +w "$out"
6+
echo 'bootstrapJs was set to: ${bootstrapJs}'
7+
# Apply project ID to configs
8+
if [ -z '${bootstrapJs}' ] || [ '${bootstrapJs}' = 'false' ]
9+
then
10+
sed -e 's/<project-id>/${projectId}/' ${.idx/dev.nix} > "$out/.idx/dev.nix"
11+
else
12+
sed -e 's/<project-id>/${projectId}/' ${.idx/dev.nix} | sed -e 's/terraform init/# terraform init/' | sed -e 's/terraform apply/# terraform apply/' > "$out/.idx/dev.nix"
13+
echo '${bootstrapJs}' > "$out/lib/bootstrap.js"
14+
echo '{"projects":{"default":"${projectId}"}}' > "$out/.firebaserc"
15+
fi
16+
# Remove the template files themselves and any connection to the template's
17+
# Git repository
18+
rm -rf "$out/.git" "$out/idx-template".{nix,json} "$out/node_modules"
19+
'';
20+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import 'dart:js_interop';
2+
3+
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
4+
import 'package:flutter/foundation.dart'
5+
show TargetPlatform, defaultTargetPlatform, kIsWeb;
6+
7+
extension type BootstrapFirebaseOptions._(JSObject _) implements JSObject {
8+
external String get apiKey;
9+
external String get authDomain;
10+
external String get databaseURL;
11+
external String get projectId;
12+
external String get storageBucket;
13+
external String get messagingSenderId;
14+
external String get appId;
15+
external String get measurementId;
16+
}
17+
18+
extension type BootstrapOptions._(JSObject _) implements JSObject {
19+
external String get geminiApiKey;
20+
external BootstrapFirebaseOptions get firebase;
21+
}
22+
23+
@JS()
24+
// ignore: non_constant_identifier_names
25+
external BootstrapOptions get APP_TEMPLATE_BOOTSTRAP;
26+
27+
class DefaultFirebaseOptions {
28+
29+
static FirebaseOptions get currentPlatform {
30+
if (kIsWeb) {
31+
return web;
32+
}
33+
switch (defaultTargetPlatform) {
34+
case TargetPlatform.android:
35+
throw UnsupportedError(
36+
'DefaultFirebaseOptions have not been configured for android - '
37+
'you can reconfigure this by running the FlutterFire CLI again.',
38+
);
39+
case TargetPlatform.iOS:
40+
throw UnsupportedError(
41+
'DefaultFirebaseOptions have not been configured for ios - '
42+
'you can reconfigure this by running the FlutterFire CLI again.',
43+
);
44+
case TargetPlatform.macOS:
45+
throw UnsupportedError(
46+
'DefaultFirebaseOptions have not been configured for macos - '
47+
'you can reconfigure this by running the FlutterFire CLI again.',
48+
);
49+
case TargetPlatform.windows:
50+
throw UnsupportedError(
51+
'DefaultFirebaseOptions have not been configured for windows - '
52+
'you can reconfigure this by running the FlutterFire CLI again.',
53+
);
54+
case TargetPlatform.linux:
55+
throw UnsupportedError(
56+
'DefaultFirebaseOptions have not been configured for linux - '
57+
'you can reconfigure this by running the FlutterFire CLI again.',
58+
);
59+
// ignore: no_default_cases
60+
default:
61+
throw UnsupportedError(
62+
'DefaultFirebaseOptions are not supported for this platform.',
63+
);
64+
}
65+
}
66+
67+
static FirebaseOptions web = FirebaseOptions(
68+
apiKey: APP_TEMPLATE_BOOTSTRAP.firebase.apiKey,
69+
appId: APP_TEMPLATE_BOOTSTRAP.firebase.appId,
70+
messagingSenderId: APP_TEMPLATE_BOOTSTRAP.firebase.messagingSenderId,
71+
projectId: APP_TEMPLATE_BOOTSTRAP.firebase.projectId,
72+
authDomain: APP_TEMPLATE_BOOTSTRAP.firebase.authDomain,
73+
storageBucket: APP_TEMPLATE_BOOTSTRAP.firebase.storageBucket,
74+
);
75+
}

0 commit comments

Comments
 (0)