How can I make icon child and text child appear only if the items equal 1 or greater
I am trying to hide the minus button and the 0 (which shows how many items) if the total equals 0. So only show the minus icon and the total items only if it is 1 or greater and make them invisible if they are 0.
import 'package:flutter/material.dart';
class ClassName extends StatefulWidget {
@override
_ClassNameState createState() => _ClassNameState();
}
class _ClassNameState extends State<ClassName> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
void _decrementCounter() {
setState(() {
if (_counter != 0)
_counter--;
});
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 7.0, top: 7.0),
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
image: DecorationImage(fit: BoxFit.fill,image:
AssetImage("image.png"))
),
),
),
Text("Black t-shirt", style:
TextStyle(fontWeight: FontWeight.bold),),
Spacer(),
Padding(
padding: const EdgeInsets.only(top: 52.0),
child: Column(
children: <Widget>[
Text("£17.99", style: TextStyle(fontWeight:
FontWeight.bold),),
SizedBox(height: 5.0,),
Row(
children: <Widget>[
IconButton(icon:
Icon(Icons.remove_circle_outline, color: Colors.blue,), onPressed:
_decrementCounter),
Text('$_counter'),
IconButton(icon: Icon(Icons.control_point,
color: Colors.blue,), onPressed: _incrementCounter),
],
)
],
),
),
],
Aucun commentaire:
Enregistrer un commentaire