super_strapi

Creator: coderz1093

Last updated:

0 purchases

super_strapi Image
super_strapi Images

Languages

Categories

Add to Cart

Description:

super strapi

A Strapi library for Dart developers should be used with package simple_strapi. with this package you can generate dart classes from strapi models and make basic find, findOne, count.. etc queries, as well as complex graph queries.
Usage #
Add as a dev dependency #
in your pubspec.yaml
dev_dependencies:
super_strapi: <latest_version>
copied to clipboard
generating dart classes from strapi models #
If you have a strapi project at /some/strapi/project/path, run the super_strapi like this
flutter pub run super_strapi -i /some/strapi/project/path/ -o /output/folder/path
copied to clipboard

📝 NOTE: if you need to use the output with plain dart project use dart pub

dart pub run super_strapi -i /some/strapi/project/path/ -o /output/folder/path
copied to clipboard

📝 NOTE: as not all packages from pub support nullsafety this command should be accompanied with --no-sound-null-safety flag

dart pub run --no-sound-null-safety super_strapi -i /some/strapi/project/path/ -o /output/folder/path
copied to clipboard
Above command will generate dart/flutter project which will contain all the data models and helper classes.
If you have a collection type called Restaurant in your strapi project the generated dart project will have a Restaurant class, a Restaurants class with all helper methods so you could do find multiple with
final restaurants = await Restaurants.findMultiple();
copied to clipboard
or find one restaraunt with
final restaurant = await Restaurants.findOne("<id of the object>");
copied to clipboard
creating new restaurant #
final newRestaurant = Restaurant.fresh(/* set all the resturant properties*/);
final createdRestaurant = await Restaurants.create(newRestaurant);
copied to clipboard
updating a existing restaurant #
///use copyWith methods to change/update values
final newRestaurant = oldResturant.copyWith(/* set all the resturant properties*/);
///or to remove a value i.e set it null use setNull method, use this method to remove a value setting null with copyWith method doesn't update it to null on the server
final newRestaurant = oldResturant.setNull(/* set properties null*/);
final updatedRestaurant = await Restaurants.update(newRestaurant);
copied to clipboard
Graph queries #
Complex graph queries is supported in the package simple_strapi, but they're still complex, super strapi comes handy in doing complex graph queries, graph queries are always about stating required fields in the response.
if you a collection named Restaurant with references to some other collections named Country, and you need to query the restaurants which belongs to country named india, what you can do is
final query = StrapiCollectionQuery(
cllectionName: Restaurant.collectionName,
requiredFields: Restaurant.fields(),
);
//now filter the country
//use whereModelField if the reference is a single reference
query.whereModelField(
field: Restaurant.fields.country,
query: StrapiModelQuery(
requiredFields:Country.fields(),
)..whereField(
field: Country.fields.name,
query: StrapiFieldQuery.equalTo,
value:"india"
)
);
// execute the query
final restaurants = await Restaurants.executeQuery(query);
copied to clipboard
PS: more details will be added to this documentation in coming days

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.