Flutter | Using simple setState() to build a shopping cart example
Cart management can also be done using the simplest form of state management in Flutter i.e. setState()
Published in
6 min readMar 4, 2020
With all the complex architectures for maintaining states, it is always good (as a beginner) to start building with the most basic approach.
This article discusses the simplest state management approach in Flutter to build a static, two page cart management application.
We will be building something like this:
Code alert!
Let’s see how can we build something similar to the grid screen above
First let us create two lists, one for populating the gridview, and one for adding items to the cart.
List<Dish> _dishes = List<Dish>();
List<Dish> _cartList = List<Dish>();
Create a new dart file and create the Dish class in that file
import 'package:flutter/material.dart';
class Dish {
final String name;
final IconData icon;
final Color color;
Dish({this.name, this.icon, this.color});
}