Dart: Scalable Application Development by Davy Mitchell & Sergey Akopkokhyants & Ivo Balbaert

Dart: Scalable Application Development by Davy Mitchell & Sergey Akopkokhyants & Ivo Balbaert

Author:Davy Mitchell & Sergey Akopkokhyants & Ivo Balbaert [Mitchell, Davy]
Language: eng
Format: azw3
Publisher: Packt Publishing
Published: 2017-06-09T04:00:00+00:00


We will call getProducts from the model in the constructor especially to return data from the server and when the data is ready, we will call the _init method to initialize our application. The readQuantity method is called for the first time to check and return the quantity of the product saved in the cookie. Later in the code, we will call calculateAmount of the product based on the quantity and price, as shown in the following code:

ShoppingController(this.tBody, this.totalAmount, this.service, this.storage) { model.getProducts().then((List<Product> products) { _products = products; _init(); }); } _init() { update().then((value) { draw(); drawTotal(); }); } Future update() { return Future.forEach(_products, (Product product) { // Read quantity of product from cookie return readQuantity(product); }); } Future readQuantity(Product product) { return storage.getItem(Product.toCookieName(product)) .then((String quantity) { if (quantity != null && quantity.length > 0) { product.quantity = int.parse(quantity); } else { product.quantity = 0; } }); } //…



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.