From 0563e50b9ab4f92e42f8be9fe08e23408c5ac4ee Mon Sep 17 00:00:00 2001 From: Moe Date: Thu, 28 Apr 2022 13:16:41 +0700 Subject: [PATCH] Add controller parameter to enable/disable button on cartbox --- lib/components/cart_box.dart | 86 +++++++++++++++++++++++------------- lib/screens/cart.dart | 2 + 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/lib/components/cart_box.dart b/lib/components/cart_box.dart index f1fd933..45abcff 100644 --- a/lib/components/cart_box.dart +++ b/lib/components/cart_box.dart @@ -2,8 +2,18 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; class CartBox extends StatefulWidget { - const CartBox({Key? key, required this.imageUrl, required this.title, required this.quantity, required this.plus, required this.minus, required this.remove}) : super(key: key); + const CartBox({ + Key? key, + required this.controller, + required this.imageUrl, + required this.title, + required this.quantity, + required this.plus, + required this.minus, + required this.remove + }) : super(key: key); + final bool controller; final String imageUrl; final String title; final int quantity; @@ -54,7 +64,7 @@ class _CartBoxState extends State { child: Column( children: [ Container( - margin: const EdgeInsets.only(left: 10.0, right: 10.0), + margin: const EdgeInsets.only(left:10.0, right: 10.0), child: Text( widget.title, style: const TextStyle( @@ -65,35 +75,51 @@ class _CartBoxState extends State { ), ), const SizedBox(height: 10,), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - ElevatedButton( - onPressed: (){ - widget.plus(); - }, - child: const Text("+"), - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(const Color(0xff8B0000)), + widget.controller == true ? Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + onPressed: (){ + widget.plus(); + }, + child: const Text("+"), + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(const Color(0xff8B0000)), + ) + ), + Text(widget.quantity.toString(), + style: const TextStyle( + fontSize: 15, + color: Colors.white, + fontWeight: FontWeight.w400) + ), + ElevatedButton( + onPressed: (){ + widget.minus(); + }, + child: const Text("-"), + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(const Color(0xff8B0000)), + ) ) - ), - Text(widget.quantity.toString(), - style: const TextStyle( - fontSize: 15, - color: Colors.white, - fontWeight: FontWeight.w400) - ), - ElevatedButton( - onPressed: (){ - widget.minus(); - }, - child: const Text("-"), - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(const Color(0xff8B0000)), - ) - ) - ], - ) + ], + ) + : Container( + margin: const EdgeInsets.only(left: 10.0, right: 10.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + "Quantity : ${widget.quantity.toString()}", + style: const TextStyle( + fontSize: 15, + color: Colors.white, + fontWeight: FontWeight.w400 + ), + ), + ], + ), + ), ], ), ), diff --git a/lib/screens/cart.dart b/lib/screens/cart.dart index e709261..ca7d3c6 100644 --- a/lib/screens/cart.dart +++ b/lib/screens/cart.dart @@ -38,6 +38,7 @@ class _CartState extends State { var productData = snapshotx.data; if (productData != null) { return CartBox( + controller: true, imageUrl: 'https://nekoya.moe.team/img/' + productData[0]['IMAGE'], title: productData[0]['TITLE'], quantity: data[index]["quantity"], @@ -64,6 +65,7 @@ class _CartState extends State { } return CartBox( + controller: true, imageUrl: 'https://i.ibb.co/QJFLZC4/La-Darknesss-Portrait.webp', title: 'Loading...', quantity: 0,