Add controller parameter to enable/disable button on cartbox

This commit is contained in:
Moe Poi ~ 2022-04-28 13:16:41 +07:00
parent 72fbe5f798
commit 0563e50b9a
2 changed files with 58 additions and 30 deletions

View file

@ -2,8 +2,18 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class CartBox extends StatefulWidget { 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 imageUrl;
final String title; final String title;
final int quantity; final int quantity;
@ -54,7 +64,7 @@ class _CartBoxState extends State<CartBox> {
child: Column( child: Column(
children: [ children: [
Container( Container(
margin: const EdgeInsets.only(left: 10.0, right: 10.0), margin: const EdgeInsets.only(left:10.0, right: 10.0),
child: Text( child: Text(
widget.title, widget.title,
style: const TextStyle( style: const TextStyle(
@ -65,35 +75,51 @@ class _CartBoxState extends State<CartBox> {
), ),
), ),
const SizedBox(height: 10,), const SizedBox(height: 10,),
Row( widget.controller == true ? Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
ElevatedButton( ElevatedButton(
onPressed: (){ onPressed: (){
widget.plus(); widget.plus();
}, },
child: const Text("+"), child: const Text("+"),
style: ButtonStyle( style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(const Color(0xff8B0000)), backgroundColor: MaterialStateProperty.all<Color>(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<Color>(const Color(0xff8B0000)),
)
) )
), ],
Text(widget.quantity.toString(), )
style: const TextStyle( : Container(
fontSize: 15, margin: const EdgeInsets.only(left: 10.0, right: 10.0),
color: Colors.white, child: Row(
fontWeight: FontWeight.w400) mainAxisAlignment: MainAxisAlignment.start,
), children: [
ElevatedButton( Text(
onPressed: (){ "Quantity : ${widget.quantity.toString()}",
widget.minus(); style: const TextStyle(
}, fontSize: 15,
child: const Text("-"), color: Colors.white,
style: ButtonStyle( fontWeight: FontWeight.w400
backgroundColor: MaterialStateProperty.all<Color>(const Color(0xff8B0000)), ),
) ),
) ],
], ),
) ),
], ],
), ),
), ),

View file

@ -38,6 +38,7 @@ class _CartState extends State<Cart> {
var productData = snapshotx.data; var productData = snapshotx.data;
if (productData != null) { if (productData != null) {
return CartBox( return CartBox(
controller: true,
imageUrl: 'https://nekoya.moe.team/img/' + productData[0]['IMAGE'], imageUrl: 'https://nekoya.moe.team/img/' + productData[0]['IMAGE'],
title: productData[0]['TITLE'], title: productData[0]['TITLE'],
quantity: data[index]["quantity"], quantity: data[index]["quantity"],
@ -64,6 +65,7 @@ class _CartState extends State<Cart> {
} }
return CartBox( return CartBox(
controller: true,
imageUrl: 'https://i.ibb.co/QJFLZC4/La-Darknesss-Portrait.webp', imageUrl: 'https://i.ibb.co/QJFLZC4/La-Darknesss-Portrait.webp',
title: 'Loading...', title: 'Loading...',
quantity: 0, quantity: 0,