flutter_fit_utils_provider

Last updated:

0 purchases

flutter_fit_utils_provider Image
flutter_fit_utils_provider Images
Add to Cart

Description:

flutter fit utils provider

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.

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
copied to clipboard

Get dependencies

flutter pub get
copied to clipboard
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 !
/// Provider for [User] data.
class UserProvider extends DataProvider<User> {
/// Creates a new [UserProvider].
UserProvider(super.service, super.factoryFunc);

@override
bool isInstanceValid(User instance) {
/// Implement your logic here...
return instance.name != "Bob";
}
}
copied to clipboard
If you need, you can override methods to implement your own logic.
/// Provider for [User] data.
class UserProvider extends DataProvider<User> {
/// Creates a new [UserProvider].
UserProvider(super.service, super.factoryFunc);

@override
Future<void> initialize({dynamic data, String userId = ""}) async {
/// Your own logic here.
}

@override
bool isInstanceValid(User instance) {
/// Implement your logic here...
return instance.name != "Bob";
}
}
copied to clipboard
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.
class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return StreamBuilder<bool>(
stream: context.read<UserProvider>().initializationStream,
builder: (context, snapshot) {
if (!context.watch<UserProvider>().initialized) {
return const CircularProgressIndicator();
}

// Show your UI here.
return const SizedBox.shrink();
},
);
}
}
copied to clipboard
Additional information #
Feel free to give any feedback ! This package is also open to contributions.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.