Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating common classes for client and server apps


In distributed apps such as the client-server pattern, you often want to work with the same model classes on both ends. Why? Because client input needs to be validated at the client side and for this, we need the model in the client app. Data has to pass through the model before being stored so that if we want to store the data in a client database (indexed_db) as well as in a server data store, we need the model on both the sides.

How to do it...

You can see how common classes are created for client and server apps in the client_server_db app. This is a to-do application; the client is started from web/app.html and the server is started from bin/server.dart. The client stores the to-do data in indexed_db, while the server stores the data in memory. Both client and server need the model classes.

The project structure is shown in the following screenshot:

Common library

How it works...

If you want to be able to import your common model library...