Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created June 19, 2019 16:37
Show Gist options
  • Save aaronksaunders/d7776a4c149cb62cfc589a7467ca7b85 to your computer and use it in GitHub Desktop.
Save aaronksaunders/d7776a4c149cb62cfc589a7467ca7b85 to your computer and use it in GitHub Desktop.
Markdium-Flutter Tabs w/ State Management
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