Skip to content

Commit 36a9c52

Browse files
authored
feat: add the data bundle sample (#36)
1 parent 68997de commit 36a9c52

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

packages/firebase_snippets_app/lib/snippets/firestore.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
// ignore_for_file: non_constant_identifier_names, avoid_print
1616

1717
import 'dart:math';
18+
import 'dart:typed_data';
1819

1920
import 'package:cloud_firestore/cloud_firestore.dart';
2021
import 'package:firebase_snippets_app/model/firestore_add_data_custom_objects_snippet.dart';
2122
import 'package:firebase_snippets_app/model/restaurant.dart';
2223
import 'package:firebase_snippets_app/snippets/snippet_base.dart';
24+
import 'package:http/http.dart' as http;
2325

2426
class FirestoreSnippets extends DocSnippet {
2527
@override
@@ -102,9 +104,26 @@ class FirestoreSnippets extends DocSnippet {
102104
// [END data_model_sub_collections]
103105
}
104106

105-
void dataBundles_loadingClientBundles() {
107+
void dataBundles_loadingClientBundles() async {
106108
// [START data_bundles_loading_client_bundles]
107-
// TODO - currently in scratch file
109+
// Get a bundle from a server
110+
final url = Uri.https('example.com', '/create-bundle');
111+
final response = await http.get(url);
112+
String body = response.body;
113+
final buffer = Uint8List.fromList(body.codeUnits);
114+
115+
// Load a bundle from a buffer
116+
LoadBundleTask task = FirebaseFirestore.instance.loadBundle(buffer);
117+
await task.stream.toList();
118+
119+
// Use the cached named query
120+
final results = await FirebaseFirestore.instance.namedQueryGet(
121+
"latest-stories-query",
122+
options: const GetOptions(
123+
source: Source.cache,
124+
),
125+
);
126+
108127
// [END data_bundles_loading_client_bundles]
109128
}
110129

packages/firebase_snippets_app/pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,13 @@ packages:
707707
source: hosted
708708
version: "2.3.0"
709709
http:
710-
dependency: transitive
710+
dependency: "direct main"
711711
description:
712712
name: http
713-
sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
713+
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
714714
url: "https://pub.dev"
715715
source: hosted
716-
version: "1.2.1"
716+
version: "1.2.2"
717717
http_multi_server:
718718
dependency: transitive
719719
description:

packages/firebase_snippets_app/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dependencies:
4545
crypto: ^3.0.1
4646
firebase_crashlytics: ^3.3.0
4747
firebase_auth_platform_interface: ^7.3.0
48+
http: ^1.2.2
4849
win32: ^5.5.4
4950

5051
dev_dependencies:

0 commit comments

Comments
 (0)