Add getx example to FAQ (#2077)

This commit is contained in:
Elmarakbeno 2022-09-24 08:06:49 +02:00 committed by GitHub
parent 31d7faa927
commit 226aead4c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -37,6 +37,16 @@ void main() {
} }
``` ```
Your widgets would then have access to the database using `Provider.of<MyDatabase>(context)`. Your widgets would then have access to the database using `Provider.of<MyDatabase>(context)`.
### GetX
If you're using the [GetX](https://pub.dev/packages/get) package, you can add it as a service that manages the database instance:.
```dart
void main() {
Get.put(MyDatabase());
runApp(MyFlutterApp());
}
```
Your widgets would then have access to the database using `Get.find<MyDatabase>().your_method`.
### A more complex architecture ### A more complex architecture
If you're strict on keeping your business logic out of the widget layer, you probably use some dependency injection If you're strict on keeping your business logic out of the widget layer, you probably use some dependency injection