I made 3 dart file that called Cart, CartSection, and EmptyCartState. here is the code from Cart
class CartPage extends StatefulWidget {
const CartPage({Key? key}) : super(key: key);
@override
_CartPageState createState() => _CartPageState();
}
class _CartPageState extends State<CartPage> {
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
it's still empty. what I want to know is how to make this Cart show CartSection if there are something in the cart and show EmptyCartState if there is nothin in the cart?
CodePudding user response:
While you like to get empty screen, you can use nullable data. I am using int
as datatype, you can use your model in this case.
class CartPage extends StatefulWidget {
const CartPage({
Key? key,
this.data,
}) : super(key: key);
final int? data;
@override
_CartPageState createState() => _CartPageState();
}
class _CartPageState extends State<CartPage> {
@override
Widget build(BuildContext context) {
return widget.data == null
? Text("empty data widget")
: Text("cart data widget");
}
}
Visit dart.dev to learn more about it.