Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created June 19, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronksaunders/0fa5fc2d6a2478b27a584ad1b5a66d51 to your computer and use it in GitHub Desktop.
Save aaronksaunders/0fa5fc2d6a2478b27a584ad1b5a66d51 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);
/// The current total price of all items (assuming all items cost $42).
/// int get totalPrice => _items.length * 42;
/// 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