0

I have this class State:

class _ItemCardState extends State<ItemCard> {
  double imgSize = 30;
  Axis expanded = Axis.horizontal;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        setState(() {
          expanded =
              expanded == Axis.horizontal ? Axis.vertical : Axis.horizontal;
          imgSize = imgSize == 30 ? 200 : 30;
        });
      },
      child: Card(
        margin: const EdgeInsets.all(5.0),
        child: Padding(
          padding: const EdgeInsets.all(15),
          child: Flex(
            direction: expanded,
            children: [
              Image.network(
                'http://cdn.shopify.com/s/files/1/0565/0697/4379/articles/Cafe-expresso-sin-maquina_1200x1200.jpg?v=1621619617',
                width: imgSize,
              ),
              Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(widget.product['name'],
                          style: const TextStyle(fontSize: 20)),
                      Text(widget.product['price'] + ' \$',
                          style: const TextStyle(fontSize: 15)),
                    ],
                  ),
                  Text(widget.product['ingredients'],
                      style: const TextStyle(fontSize: 15, color: Colors.grey)),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

I want the Flex Widget change direction onTap, it works. But the column inside is not taking all space avaible in the crossAxis. If I put an Expanded Widget it stops working,... I've tried Flexibles, but somehow it didnt work. I used ListTiles also, but I couldnt make it work.

Any idea on how to do it?

screenshot

1 Answer 1

0

well. I resolved it putting the Flex Widget inside a SizedBox and then I was able to use Flexible>fit:FlexFit.tigth:

SizedBox(
        height: 300,
        child: Flex(
          direction: expanded,
          children: [
            Image.network(
              'http://cdn.shopify.com/s/files/1/0565/0697/4379/articles/Cafe-expresso-sin-maquina_1200x1200.jpg?v=1621619617',
              width: imgSize,
            ),
            Flexible(
              fit: FlexFit.tight,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(widget.product['name'],
                          style: const TextStyle(fontSize: 20)),
                      Text(widget.product['price'] + ' \$',
                          style: const TextStyle(fontSize: 15)),
                    ],
                  ),
                  Text(widget.product['ingredients'],
                      style: const TextStyle(
                          fontSize: 15, color: Colors.grey)),
                ],
              ),
            )
          ],
        ),
      ),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.