Search code examples
flutterflutter-layout

How to position a dot right next to an icon?


enter image description here

Hi, may I know is there got anyway to set the margin or padding closer to the iconUser, I want to get the circle shape at the top of the iconUser, been tried set margin or padding but still unable to solve this issues.

   children: <Widget>[
                    SizedBox(width: 10,),
                    GestureDetector(
                      onTap: (){},
                      child: Image.asset("assets/ic_user_center.png",height: 16.0,width: 16.0,)
                    )
                  ],
                ),
                Padding(
                  padding: const EdgeInsets.only(bottom: 8.0),
                  child: Container(
                    width: 5.0,
                    height: 5.0,
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: Colors.white
                    ),
                  ),
                )
              ],
            ),

Solution

  • Another way to achieve that is by place image as BackgroundImage inside Container() decoration property.

    Container(
       width: 48,
       height: 48,
       decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: Colors.grey,
          image: DecorationImage(
             image: NetworkImage(imageUrl),
             fit: BoxFit.cover,
          ),
       ),
       child: Align(
          alignment: Alignment.topRight,
          child: Container(
             width: 20,
             height: 20,
             decoration: BoxDecoration(
             shape: BoxShape.circle,
             color: isOnline
                ? const Color(0xFF44B513)
                : Colors.grey,
             border: const Border.fromBorderSide(
                BorderSide(color: Colors.white, width: 3),
             ),
          ),
       ),
    ),
    

    enter image description here

    For negative margin, use Stack() and set clip to Clip.none

    Stack(
      clipBehavior: Clip.none,
      children: [
        myIcon(),
        Positioned(
          right: -6,
          top: -6,
          child: Container(
            width: 20,
            height: 20,
            decoration: const BoxDecoration(
              shape: BoxShape.circle,
              color: const Color(0xFF44B513),
            ),
          ),
        ),
      ],
    ),