|
1 | 1 | # Quick Start
|
2 | 2 |
|
3 | 3 | 1. Add the packages:
|
4 |
| - ```yaml |
5 |
| - dependencies: |
6 |
| - # Or brick_offline_first_with_graphql |
7 |
| - brick_offline_first_with_rest: |
8 |
| - sqflite: # optional |
9 |
| - dev_dependencies: |
10 |
| - # Or brick_offline_first_with_graphql_build: any |
11 |
| - brick_offline_first_with_rest_build: |
12 |
| - build_runner: |
13 |
| - ``` |
| 4 | + ```yaml |
| 5 | + dependencies: |
| 6 | + # Or brick_offline_first_with_supabase |
| 7 | + brick_offline_first_with_rest: |
| 8 | + sqflite: # optional |
| 9 | + dev_dependencies: |
| 10 | + # Or brick_offline_first_with_graphql_build: any |
| 11 | + # Or brick_offline_first_with_supabase_build: any |
| 12 | + brick_offline_first_with_rest_build: |
| 13 | + build_runner: |
| 14 | + ``` |
14 | 15 | 1. Configure your app directory structure to match Brick's expectations:
|
15 |
| - ```bash |
16 |
| - mkdir -p lib/brick/adapters lib/brick/db; |
17 |
| - ``` |
| 16 | + ```bash |
| 17 | + mkdir -p lib/brick/adapters lib/brick/db; |
| 18 | + ``` |
18 | 19 | 1. Add [models](docs/data/models) that contain your app logic. Models **must be** saved with the `.model.dart` suffix (i.e. `lib/brick/models/person.model.dart`).
|
19 | 20 | 1. Run `dart run build_runner build` to generate your models and [sometimes migrations](docs/sqlite.md#intelligent-migrations). Rerun after every new model change or `dart run build_runner watch` for automatic generations. You'll need to run this again after your first migration.
|
20 | 21 | 1. Extend [an existing repository](docs/data/repositories) or create your own:
|
21 |
| - ```dart |
22 |
| - // lib/brick/repository.dart |
23 |
| - import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart'; |
24 |
| - import 'package:brick_rest/brick_rest.dart'; |
25 |
| - import 'package:brick_sqlite/brick_sqlite.dart'; |
26 |
| - import 'package:my_app/brick/brick.g.dart'; |
27 |
| - import 'package:sqflite/sqflite.dart' show databaseFactory; |
28 |
| - import 'package:my_app/brick/db/schema.g.dart'; |
29 |
| - export 'package:brick_core/query.dart' show And, Or, Query, QueryAction, Where, WherePhrase; |
30 |
| -
|
31 |
| - class Repository extends OfflineFirstWithRestRepository { |
32 |
| - Repository() |
33 |
| - : super( |
34 |
| - migrations: migrations, |
35 |
| - restProvider: RestProvider( |
36 |
| - 'http://0.0.0.0:3000', |
37 |
| - modelDictionary: restModelDictionary, |
38 |
| - ), |
39 |
| - sqliteProvider: SqliteProvider( |
40 |
| - _DB_NAME, |
41 |
| - databaseFactory: databaseFactory, |
42 |
| - modelDictionary: sqliteModelDictionary, |
43 |
| - ), |
44 |
| - offlineQueueManager: RestRequestSqliteCacheManager( |
45 |
| - 'brick_offline_queue.sqlite', |
46 |
| - databaseFactory: databaseFactory, |
47 |
| - ), |
48 |
| - ); |
49 |
| - } |
50 |
| - ``` |
| 22 | + |
| 23 | + ```dart |
| 24 | + // lib/brick/repository.dart |
| 25 | + import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart'; |
| 26 | + import 'package:brick_rest/brick_rest.dart'; |
| 27 | + import 'package:brick_sqlite/brick_sqlite.dart'; |
| 28 | + import 'package:my_app/brick/brick.g.dart'; |
| 29 | + import 'package:sqflite/sqflite.dart' show databaseFactory; |
| 30 | + import 'package:my_app/brick/db/schema.g.dart'; |
| 31 | + export 'package:brick_core/query.dart' show And, Or, Query, QueryAction, Where, WherePhrase; |
| 32 | +
|
| 33 | + class Repository extends OfflineFirstWithRestRepository { |
| 34 | + Repository() |
| 35 | + : super( |
| 36 | + migrations: migrations, |
| 37 | + restProvider: RestProvider( |
| 38 | + 'http://0.0.0.0:3000', |
| 39 | + modelDictionary: restModelDictionary, |
| 40 | + ), |
| 41 | + sqliteProvider: SqliteProvider( |
| 42 | + _DB_NAME, |
| 43 | + databaseFactory: databaseFactory, |
| 44 | + modelDictionary: sqliteModelDictionary, |
| 45 | + ), |
| 46 | + offlineQueueManager: RestRequestSqliteCacheManager( |
| 47 | + 'brick_offline_queue.sqlite', |
| 48 | + databaseFactory: databaseFactory, |
| 49 | + ), |
| 50 | + ); |
| 51 | + } |
| 52 | + ``` |
| 53 | + |
51 | 54 | 1. Profit.
|
52 | 55 |
|
| 56 | +## Integrations |
| 57 | + |
| 58 | +- [With Rest](offline_first/offline_first_with_rest_repository.md) |
| 59 | +- [With GraphQL](offline_first/offline_first_with_graphql_repository.md) |
| 60 | +- [With Supabase](offline_first/offline_first_with_supabase_repository.md) |
| 61 | + |
53 | 62 | ## Learn
|
54 | 63 |
|
55 |
| -* Video: [Brick Architecture](https://www.youtube.com/watch?v=2noLcro9iIw). An explanation of Brick parlance with a supplemental analogy. |
56 |
| -* Video: [Brick Basics](https://www.youtube.com/watch?v=jm5i7e_BQq0). An overview of essential Brick mechanics. |
57 |
| -* Example: [Simple Associations using the OfflineFirstWithGraphql domain](https://github.com/GetDutchie/brick/blob/main/example_graphql) |
58 |
| -* Example: [Simple Associations using the OfflineFirstWithRest domain](https://github.com/GetDutchie/brick/blob/main/example) |
59 |
| -* Tutorial: [Setting up a simple app with Brick](http://www.flutterbyexample.com/#/posts/2_adding_a_repository) |
| 64 | +- Video: [Brick Architecture](https://www.youtube.com/watch?v=2noLcro9iIw). An explanation of Brick parlance with a supplemental analogy. |
| 65 | +- Video: [Brick Basics](https://www.youtube.com/watch?v=jm5i7e_BQq0). An overview of essential Brick mechanics. |
| 66 | +- Example: [Simple Associations using the OfflineFirstWithGraphql domain](https://github.com/GetDutchie/brick/blob/main/example_graphql) |
| 67 | +- Example: [Simple Associations using the OfflineFirstWithRest domain](https://github.com/GetDutchie/brick/blob/main/example) |
| 68 | +- Tutorial: [Setting up a simple app with Brick](http://www.flutterbyexample.com/#/posts/2_adding_a_repository) |
60 | 69 |
|
61 | 70 | ## Glossary
|
62 | 71 |
|
63 |
| -* **source** - external information warehouse that delivers unrefined data |
64 |
| -* [**Provider**](data/providers.md) - fetches from and pushes to a `source` |
65 |
| -* [**Repository**](data/repositories.md) - manages `Provider`(s) and determines which provider results to send |
66 |
| -* **Adapter** - normalizes data input and output between `Provider`s |
67 |
| -* [**Model**](data/models.md) - business logic unique to the app. Fetched by the `Repository`, and if merited by the `Repository` implementation, the `Provider`. |
68 |
| -* **ModelDictionary** - guides a `Provider` to the `Model`'s `Adapter`. Unique per `Provider`. |
69 |
| -* **field** - single, accessible property of a model. For example, `final String id` |
70 |
| -* **deserialize** - convert raw data _from_ a provider |
71 |
| -* **serialize** - convert a model instance _to_ raw data for a provider |
| 72 | +- **source** - external information warehouse that delivers unrefined data |
| 73 | +- [**Provider**](data/providers.md) - fetches from and pushes to a `source` |
| 74 | +- [**Repository**](data/repositories.md) - manages `Provider`(s) and determines which provider results to send |
| 75 | +- **Adapter** - normalizes data input and output between `Provider`s |
| 76 | +- [**Model**](data/models.md) - business logic unique to the app. Fetched by the `Repository`, and if merited by the `Repository` implementation, the `Provider`. |
| 77 | +- **ModelDictionary** - guides a `Provider` to the `Model`'s `Adapter`. Unique per `Provider`. |
| 78 | +- **field** - single, accessible property of a model. For example, `final String id` |
| 79 | +- **deserialize** - convert raw data _from_ a provider |
| 80 | +- **serialize** - convert a model instance _to_ raw data for a provider |
72 | 81 |
|
73 | 82 | ## FAQ
|
74 | 83 |
|
|
0 commit comments