Skip to content

Commit d93bfab

Browse files
authored
cloud-storage snippets (#4)
* finish cloud storage snippets Co-authored-by: Eric Windmill <[email protected]>
1 parent e349afa commit d93bfab

File tree

4 files changed

+594
-6
lines changed

4 files changed

+594
-6
lines changed

README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,62 @@
1-
21
# Firebase Flutter Snippets
32

43
This repository holds code snippets used in Flutter documentation
54
on [firebase.google.com](https://firebase.google.com/docs/).
65

7-
These snippets are part of our documentation and best read in the context of a documentation page rather than used directly.
8-
9-
Each snippet has a "region tag" which is defined by `// [START tag]` and `// [END tag]` comments. The code between the tags can be included in our documentation. Keeping the code on GitHub, rather than hard-coded into the HTML of our documentation, allows us to ensure the code is correct and up to date.
6+
These snippets are part of our documentation and best read in the context of a
7+
documentation page rather than used directly.
108

9+
Each snippet has a "region tag" which is defined by `// [START tag]`
10+
and `// [END tag]` comments. The code between the tags can be included in our
11+
documentation. Keeping the code on GitHub, rather than hard-coded into the HTML
12+
of our documentation, allows us to ensure the code is correct and up to date.
1113

1214
## Set up / Running Instructions - WIP
15+
1316
- installed flutter, intellij, intellij plugins
1417
- created firebase project, downloaded firebase CLI, installed flutterfirecli
1518
- `flutter create firestore-snippets && cd firestore-snippets`
1619
- `flutterfire-configure`
1720

21+
## Snippet structure
22+
23+
**Note**: Most snippets follow this structure, but in some cases multiple
24+
snippets are located in a single function. In this case, the function name
25+
represents which snippet the function name starts on.
26+
27+
Each Firebase product (that requires Flutter snippets) has its own file located
28+
in the dir `apps/firestore_snippets/lib/snippets`.
29+
30+
Each of these files defines a class called [Firebase Product Name]Snippets.
31+
These classes have a separate function for each snippet. These functions follow
32+
the naming convention of `firebaseDocsPageName_snippetTitle`. For
33+
example: `FirestoreSnippets.getStarted_addData`. Each snippet is also wrapped by
34+
comments which define the beginning and ending of the snippet, and generally
35+
excludes the function names. The code in this region, between the two comments,
36+
is the code that appears in the Firebase documentation.
37+
38+
Example:
39+
40+
See translated snippet in
41+
the [Firebase documentation](https://firebase.google.com/docs/firestore/quickstart#add_data)
42+
43+
```dart
44+
void getStarted_addData() async {
45+
// [START get_started_add_data_1]
46+
// Create a new user with a first and last name
47+
final user = <String, dynamic>{
48+
"first": "Ada",
49+
"last": "Lovelace",
50+
"born": 1815
51+
};
52+
53+
// Add a new document with a generated ID
54+
db.collection("users").add(user).then((DocumentReference doc) =>
55+
print('DocumentSnapshot added with ID: ${doc.id}'));
56+
// [END get_started_add_data_1]
57+
}
58+
```
59+
1860
[comment]: <> (## Example)
1961

2062
[comment]: <> (TODO: ewindmill@ fill this in when first snippets are live.)

0 commit comments

Comments
 (0)