flutterflutter-widgetflutter-container

flutter icon is not centered in container


I was trying to center the icon in a circular background but it failed even if I use a center widget as child unless increase container size.


    Container(
                  height: 22,
                  width: 22,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    color: Color(0xffF7825C),
                  ),
                  child: Center(
                    child: Icon(
                      Icons.add,
                      color: Colors.white,
                    ),
                  ),
                ) 


Solution

  • Try this:

                 Container(
                  alignment: Alignment.center,
                  height: 22,
                  width: 22,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    color: Color(0xffF7825C),
                  ),
                  child: Icon(
                      Icons.add,
                      color: Colors.white,
                      size: 22 
                    ),
                )