Summary

The main point of working on the project that you've built in this chapter isn't the app features themselves—you could create a todo app in much simpler ways. The focus here is the architecture that you've seen in action: using an asynchronous stream of data to update the state of an app is a pattern that can help you scale your projects to enterprise levels. 

At the beginning of this chapter, you saw how to use the simple embedded application store database, or sembast, a document-based database that resides in a single file where data is stored in JSON format.

In sembast, a DatabaseFactory allows you to open a database where each database is a file and stores are locations in the database where you can save and retrieve data.

To insert a new item in a sembast database, you need to call the add() method over the store, passing the database and the map of the object you want to insert. A finder is a helper for filtering and ordering data into a given store.

To delete an existing item, you call the delete() method on the store: this takes the database and a finder as parameters. 

To update an existing item, you call the update() method on the store: this takes the database, a map of the updated object, and the finder. To retrieve data, you use a finder and the find() method.

Next, you saw how to leverage the BLoC pattern to manage the state of your apps. 

When using a BLoC, everything is a stream of events: the BLoC receives streams of events/data from the source, handles any required business logic, and publishes streams of data. A BLoC has two components: Sinks and Streams, both of which are part of a StreamController.

In order to use the Stream and be notified when something comes out of it, you need to listen to the Stream. Therefore, you define a listener with a StreamSubscription object that is notified every time an event related to the Stream is triggered.

The StreamBuilder widget listens to the events from the Stream and rebuilds its descendants, using the latest data in the Stream.

In the next chapter, you'll see how you can create responsive web apps with Flutter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.131.10