flutterstackflutter-positioned

how to place one container over another container - Flutter


I am trying to do this particular design for the Login page.

UI

But the result I got it is on below:

enter image description here

The code I tried is:

               Stack(
                      fit: StackFit.passthrough,
                      children: [
                        Container(height: 2, color: Colors.grey),
                        Positioned(
                          child: Center(
                            child: Transform.rotate(
                              alignment: Alignment.center,
                              angle: 45,
                              child: Container(
                                height: 18,
                                width: 18,
                                color: colorController.primaryColor.value,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),

Solution

  • Line Widget (Container with color ) size is 2 that's cause result mismatch from what you want

    fix it to this

     Stack(
       fit: StackFit.passthrough,
       children: [
         const SizedBox(
           height: 18,
           child: Divider(
             color: Colors.grey,
             height: 2,
             thickness: 2,
           ),
         ),
         Positioned(
           child: Center(
             child: Transform.rotate(
               alignment: Alignment.center,
               angle: 40,
               child: Container(
                 height: 18,
                 width: 18,
                 color: Colors.blue,
               ),
             ),
           ),
         )
       ],
     ),