Search code examples
flutterdartpadding

Why do I have extra padding in flutter?


I have written a code with a row inside which is another column. But for some reason there is this extra padding which I don't want. How can I remove it? Also, what is the cause of it. enter image description here

This is my code:

import 'package:brew_crew_firebase_tut/models/brew.dart';
import 'package:flutter/material.dart';

class BrewTile extends StatefulWidget {
  Brew brew;
  BrewTile({ super.key, required this.brew });

  @override
  State<BrewTile> createState() => _BrewTileState();
}

class _BrewTileState extends State<BrewTile> {
  @override
  Widget build(BuildContext context) {
    Brew brew = widget.brew;
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 20),
      child: Card(child: Container(
        padding: EdgeInsets.all(16.0),
        child: Row(
          children: [
            CircleAvatar(backgroundColor:Colors.brown[brew.strength], backgroundImage: AssetImage("assets/coffee_icon.png"),),
            SizedBox(width: 10,),
            Column(
              children: [
                Text(brew.name, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),),
                Text("Takes ${brew.sugars} sugars", style: TextStyle(color: Colors.grey[600]),),
              ],
              )
          ],
        ),
      ),),
    );
  }
}

It was just fine but I don't know for some reason it abruptly came there.


Solution

  • I think you need to add:

     crossAxisAlignment: CrossAxisAlignment.start
    

    To your Column, like this:

     Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
           Text(brew.name, style: TextStyle(fontSize: 20, fontWeight: 
           FontWeight.bold),),
           Text("Takes ${brew.sugars} sugars", style: TextStyle(color: 
           Colors.grey[600]),),
        ],
     )