Created
June 19, 2019 16:37
-
-
Save aaronksaunders/d7776a4c149cb62cfc589a7467ca7b85 to your computer and use it in GitHub Desktop.
Markdium-Flutter Tabs w/ State Management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:collection'; | |
import 'package:flutter/material.dart'; | |
class Item { | |
String name; | |
num price; | |
Item(this.name, this.price); | |
} | |
class CartModel extends ChangeNotifier { | |
/// Internal, private state of the cart. | |
final List _items = []; | |
/// An unmodifiable view of the items in the cart. | |
UnmodifiableListView get items => UnmodifiableListView(_items); | |
/// Adds [item] to cart. This is the only way to modify the cart from outside. | |
void add(Item item) { | |
_items.add(item); | |
// This call tells the widgets that are listening to this model to rebuild. | |
notifyListeners(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment