Skip to content

Commit 37bc19d

Browse files
authored
Merge pull request #1 from firebase/remote-config
Adds Remote Config initial files and classes
2 parents e656226 + 9daecd1 commit 37bc19d

File tree

9 files changed

+154
-16
lines changed

9 files changed

+154
-16
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_Description of what this PR is changing or adding, and why:_
2+
3+
_Issues fixed by this PR (if any):_
4+
5+
## Pre-submit checklist
6+
- [ ] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style)
7+
- [ ] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks)

.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
*.g.dart
34+
35+
# Web related
36+
lib/generated_plugin_registrant.dart
37+
38+
# Symbolication related
39+
app.*.symbols
40+
41+
# Obfuscation related
42+
app.*.map.json
43+
44+
# Android Studio will place build artifacts here
45+
/android/app/debug
46+
/android/app/profile
47+
/android/app/release

apps/firestore_snippets/lib/app.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,33 @@
1313
// limitations under the License.
1414

1515
import 'package:cloud_firestore/cloud_firestore.dart';
16+
import 'package:firebase_remote_config/firebase_remote_config.dart';
1617
import 'package:firestore_snippets/snippets/firestore.dart';
18+
import 'package:firestore_snippets/snippets/remote_config.dart';
1719
import 'package:flutter/material.dart';
1820

1921
class MyApp extends StatefulWidget {
2022
const MyApp({
2123
Key? key,
2224
required this.firestore,
25+
required this.firebaseRemoteConfig,
2326
}) : super(key: key);
2427

2528
final FirebaseFirestore firestore;
29+
final FirebaseRemoteConfig firebaseRemoteConfig;
2630

2731
@override
2832
State<MyApp> createState() => _MyAppState();
2933
}
3034

3135
class _MyAppState extends State<MyApp> {
3236
late final FirestoreSnippets _firestoreSnippets;
37+
late final RemoteConfigSnippets _remoteConfigSnippets;
3338

3439
@override
3540
void initState() {
3641
_firestoreSnippets = FirestoreSnippets(widget.firestore);
42+
_remoteConfigSnippets = RemoteConfigSnippets(widget.firebaseRemoteConfig);
3743

3844
_firestoreSnippets.runAll();
3945
super.initState();

apps/firestore_snippets/lib/main.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// [START set_up_environment]
1616
import 'package:cloud_firestore/cloud_firestore.dart';
1717
import 'package:firebase_core/firebase_core.dart';
18+
import 'package:firebase_remote_config/firebase_remote_config.dart';
1819
// [END set_up_environment]
1920

2021
import 'package:firestore_snippets/app.dart';
@@ -61,9 +62,16 @@ void main() async {
6162
db.settings = settings;
6263
// [END access_data_offline_configure_offline_persistence]
6364

65+
// [START get_started_get_singleton_object]
66+
FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.instance;
67+
// [END get_started_get_singleton_object]
68+
6469
if (!kReleaseMode) db.useFirestoreEmulator('localhost', 8080);
6570

6671
runApp(
67-
MyApp(firestore: db),
72+
MyApp(
73+
firestore: db,
74+
firebaseRemoteConfig: firebaseRemoteConfig,
75+
),
6876
);
6977
}

apps/firestore_snippets/lib/snippets/firestore.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'package:firestore_snippets/snippets/custom_snippets/firestore_add_data_c
2121
import 'package:firestore_snippets/snippets/custom_snippets/restaurant.dart';
2222
import 'package:firestore_snippets/snippets/snippet.dart';
2323

24-
class FirestoreSnippets extends DocSnippet implements Firestore {
24+
class FirestoreSnippets extends DocSnippet {
2525
@override
2626
final FirebaseFirestore db;
2727

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// ignore_for_file: non_constant_identifier_names, avoid_print
16+
17+
import 'package:firebase_remote_config/firebase_remote_config.dart';
18+
import 'package:firestore_snippets/snippets/snippet.dart';
19+
20+
class RemoteConfigSnippets extends DocSnippet {
21+
final FirebaseRemoteConfig firebaseRemoteConfig;
22+
23+
RemoteConfigSnippets(this.firebaseRemoteConfig);
24+
25+
@override
26+
void runAll() {}
27+
28+
void getStarted_setMinimumIntervalFetch() {
29+
// [START get_started_set_minimum_interval_fetch]
30+
firebaseRemoteConfig.settings.minimumFetchInterval =
31+
const Duration(milliseconds: 3600000);
32+
// [END get_started_set_minimum_interval_fetch]
33+
}
34+
35+
void getStarted_setDefaultValues() {
36+
// [START get_started_set_default_values]
37+
firebaseRemoteConfig.setDefaults(<String, dynamic>{
38+
'welcome_message': 'this is the default welcome message',
39+
});
40+
// [END get_started_set_default_values]
41+
}
42+
43+
void getStarted_getDefaultValues() {
44+
// [START get_started_get_default_values]
45+
final val = firebaseRemoteConfig.getValue("welcome_messsage");
46+
// [END get_started_get_default_values]
47+
}
48+
49+
void getStarted_fetchAndActivateValues() {
50+
// [START get_started_fetch_and_activate_values]
51+
firebaseRemoteConfig.fetchAndActivate().then((bool success) {
52+
if (success) {
53+
final updatedConfig = firebaseRemoteConfig.getAll();
54+
print("Config params updated: $updatedConfig");
55+
}
56+
});
57+
// [END get_started_fetch_and_activate_values]
58+
}
59+
}

apps/firestore_snippets/lib/snippets/snippet.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/*
16-
Base class for all Snippets
17-
*/
18-
import 'package:cloud_firestore/cloud_firestore.dart';
19-
2015
abstract class DocSnippet {
2116
void runAll();
2217
}
23-
24-
class Firestore {
25-
final FirebaseFirestore db;
26-
27-
Firestore(this.db);
28-
}

apps/firestore_snippets/pubspec.lock

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,35 @@ packages:
8484
name: firebase_core_platform_interface
8585
url: "https://pub.dartlang.org"
8686
source: hosted
87-
version: "4.2.4"
87+
version: "4.2.5"
8888
firebase_core_web:
8989
dependency: transitive
9090
description:
9191
name: firebase_core_web
9292
url: "https://pub.dartlang.org"
9393
source: hosted
94-
version: "1.5.4"
94+
version: "1.6.1"
95+
firebase_remote_config:
96+
dependency: "direct main"
97+
description:
98+
name: firebase_remote_config
99+
url: "https://pub.dartlang.org"
100+
source: hosted
101+
version: "2.0.2"
102+
firebase_remote_config_platform_interface:
103+
dependency: transitive
104+
description:
105+
name: firebase_remote_config_platform_interface
106+
url: "https://pub.dartlang.org"
107+
source: hosted
108+
version: "1.1.1"
109+
firebase_remote_config_web:
110+
dependency: transitive
111+
description:
112+
name: firebase_remote_config_web
113+
url: "https://pub.dartlang.org"
114+
source: hosted
115+
version: "1.0.7"
95116
flutter:
96117
dependency: "direct main"
97118
description: flutter
@@ -226,4 +247,4 @@ packages:
226247
version: "2.1.1"
227248
sdks:
228249
dart: ">=2.16.1 <3.0.0"
229-
flutter: ">=1.12.13+hotfix.5"
250+
flutter: ">=1.20.0"

apps/firestore_snippets/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies:
2525
sdk: flutter
2626
firebase_core: ^1.12.0
2727
cloud_firestore: ^3.1.8
28+
firebase_remote_config: ^2.0.2
2829

2930
dev_dependencies:
3031
flutter_test:

0 commit comments

Comments
 (0)