dorm_framework 1.0.0-alpha.7
Exposes classes, filters and joins to implement the dORM framework.
dORM example
A full Flutter application using dORM.
This example helps you to understand how to integrate dORM within your application using an e-commerce code sample. It contains CRUDs, joins and some commonly used database filters, such as by text, by value and by range.
It also shows how to integrate dORM models with forms, using
the flutter_form_bloc package.
Getting started
-
Clone this repository:
git clone https://github.com/beet-software/dorm.git cd dorm/dorm_framework/example -
(optional) If you want a local Firebase instance, run the following line in your command prompt:
firebase emulators:start --only database --project react-native-firebase-testingThe command above can be run verbatim, since
react-native-firebase-testingis generally used as a dummy project ID. If you already have a project you want to integrate dORM, replace it with your own project's ID.Wait for the message "All emulators ready! It is now safe to connect your app" to show up.
-
Get the dependencies and run the application:
flutter pub get flutter run
Requirements
The application shall be an e-commerce.
- An user must have an username, an email and its personal info, such as name, birthdate and an optional bio.
- A product must have a name, a description and a price.
- A cart must have a timestamp of when it was first created.
- A review must contain a text, the timestamp of when it was published and its content.
- Each user can have one cart at a time.
- Each cart can have infinite products (no inventory handling).
- Each product in a cart must have an amount (at least one item).
- A user can make infinite reviews.
- A user can review a product, a service or another user.
Usage
The first screen manages all users in the system. Tap the icon on the bottom right corner to add a new user:
After you add a couple of users, you can search them by username:
You can tap on a user to view, edit or delete its profile:
Each user has a single cart, which you can access on its respective tile:
Tap the icon on the bottom right corner to add a new order to this user's cart:
There won't be any products registered yet. Tap the icon on the top right corner to enable editing mode in this screen, where you can create, edit or delete products. When done editing, tap the icon again to reenable selection mode:
When on editing mode, tap the icon on the bottom right corner to add a new product:
Add a couple of products. You can edit or remove them:
When you reenable selection mode, you'll be able to select a product and its amount:
When selecting a couple of products and their respective amounts, go to the main screen and tap the button on the top right corner. This is the dashboard, and you can see the products ordered by each user, as well as how many products each user has ordered:
Finally, tapping on an user allows you to make a review on behalf of that user, tapping the button on the top right corner:
Add a couple of reviews and use the chips to filter them by type:
dORM integration
The screens are available on lib/screens/.
-
The
UsersScreen(users.dart) can be used to see all the users or add an user to the system.- Uses
pullAllto read all users from the system, given a username (filtering by text) - Uses
putto create a new user (creating a strong entity)
- Uses
-
The
UserScreen(user.dart) can be used to update an user and view its cart, if created.- Uses
pullto read this user with its cart, if exists - Uses
pushandpopto edit and remove this user, respectively - Uses
putto create a new cart (creating a weak entity) - Uses
pullAllto read all reviews of a given type from this user (filtering by many values) - Uses
popto remove a review
- Uses
-
The
CartScreen(cart.dart) can be used to see the products placed in its cart by an user.- Uses
pullAllto read all items of a specific cart (filtering by value) - Uses
OneToOneRelationshipto associate cart items with their respective products (1-to-1) - Uses
putto create a new item on user's cart (creating a weak entity)
- Uses
-
The
OrderScreen(order.dart) can be used to select a product and its amount to be added to a cart.- Uses
pullAllto read all products from the system (without filtering) - Uses
pushandpopto edit and remove a product, respectively - User
putto create a new product (creating a strong entity)
- Uses
-
The
DashboardScreen(dashboard.dart) can be used to view some statistics about the system.- Uses
OneToManyRelationshipcombined withOneToOneRelationshipto list all products ordered by an user - Uses
ManyToOneRelationshipto how many users have ordered a given product
- Uses
Tips
- Prefer using
pullandpullAllinstead ofpeekandpeekAll, since their stream will synchronize updates made on the model by other parts of the application. - Use the
*Dataversion of a dORM model when creating it from a form. - Don't pass a
*Modelas argument to a new screen. Instead, pass its ID and read it again.