Search code examples
androidfluttercontainers

How i can set margin in -(Minus)?


in my app i use container i push the container to the top side so i want to set minus margin but is not work

            Container(
                  margin:const EdgeInsets.fromLTRB(5, -20, 5, 0),
                  child:const Text(
                  'MyContainer',
                  style: TextStyle(
                      color: black, fontSize: 20, fontWeight: FontWeight.bold),
                  ),
             ) 

Solution

  • Wrap Container with Transform.translate.

    Transform.translate(
                offset: Offset(5, -20), 
                child: Container(
                child: const Text(
                    'MyContainer',
                    style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold),
                  ),
                ),
              )