Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s0punk/flutter_fit_utils_provider
A flutter package to easily create providers of modelable data. This package is part of the flutter_fit_utils environement.
https://github.com/s0punk/flutter_fit_utils_provider
Last synced: 29 days ago
JSON representation
A flutter package to easily create providers of modelable data. This package is part of the flutter_fit_utils environement.
- Host: GitHub
- URL: https://github.com/s0punk/flutter_fit_utils_provider
- Owner: s0punk
- License: mit
- Created: 2024-05-21T01:16:59.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-09-15T23:28:05.000Z (2 months ago)
- Last Synced: 2024-10-03T08:24:09.043Z (about 1 month ago)
- Language: Dart
- Homepage: https://pub.dev/packages/flutter_fit_utils_provider
- Size: 52.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
A flutter package to easily create providers of modelable data.
This package is part of the flutter_fit_utils environement. To know about other packages related to flutter_fit_utils, see the diagram below.![flutter_fit_utils drawio](https://github.com/s0punk/flutter_fit_utils_provider/assets/59456672/74b056f7-f85d-4635-891c-fd9feee99cfb)
## Features
This package lets you use pre-built providers, or custom ones, for your models. These providers then use services to manage your data repositories.
## Getting started
- Go inside your pubspec.yaml file
- Add this line under the dependencies:
```
flutter_fit_utils_provider: ^1.0.0
```
- Get dependencies
```
flutter pub get
```## Usage
Check out example/main.dart for the complete implementation.
### Creating a provider
Create a class that extends DataProvider or ItemsProvider. Use DataProvider if you want to provide a single modelable. On the contrary, use ItemsProvider if yout want to provide a list of modelables. It's that easy !```dart
/// Provider for [User] data.
class UserProvider extends DataProvider {
/// Creates a new [UserProvider].
UserProvider(super.service, super.factoryFunc);@override
bool isInstanceValid(User instance) {
/// Implement your logic here...
return instance.name != "Bob";
}
}
```If you need, you can override methods to implement your own logic.
```dart
/// Provider for [User] data.
class UserProvider extends DataProvider {
/// Creates a new [UserProvider].
UserProvider(super.service, super.factoryFunc);@override
Future initialize({dynamic data, String userId = ""}) async {
/// Your own logic here.
}@override
bool isInstanceValid(User instance) {
/// Implement your logic here...
return instance.name != "Bob";
}
}
```You can always create a custom provider by inheriting FitProvider or FitFormProvider.
### Waiting for the initialization of your provider
FitProviders have an initialization stream that you can listen to. This way, you can update your UI when your provider is ready.```dart
class MyApp extends StatelessWidget {
const MyApp({super.key});@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: context.read().initializationStream,
builder: (context, snapshot) {
if (!context.watch().initialized) {
return const CircularProgressIndicator();
}// Show your UI here.
return const SizedBox.shrink();
},
);
}
}
```## Additional information
Feel free to [give any feedback](https://github.com/s0punk/flutter_fit_utils_provider/issues) ! This package is also open to contributions.