|
1 |
| - |
2 | 1 | # Firebase Flutter Snippets
|
3 | 2 |
|
4 | 3 | This repository holds code snippets used in Flutter documentation
|
5 | 4 | on [firebase.google.com](https://firebase.google.com/docs/).
|
6 | 5 |
|
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. |
10 | 8 |
|
| 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. |
11 | 13 |
|
12 | 14 | ## Set up / Running Instructions - WIP
|
| 15 | + |
13 | 16 | - installed flutter, intellij, intellij plugins
|
14 | 17 | - created firebase project, downloaded firebase CLI, installed flutterfirecli
|
15 | 18 | - `flutter create firestore-snippets && cd firestore-snippets`
|
16 | 19 | - `flutterfire-configure`
|
17 | 20 |
|
| 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 | + |
18 | 60 | [comment]: <> (## Example)
|
19 | 61 |
|
20 | 62 | [comment]: <> (TODO: ewindmill@ fill this in when first snippets are live.)
|
|
0 commit comments