Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Center the text widget inside transform scale in Flutter

How can we edit the children of this widget in a widget that we use transform scale?

Expected

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Transform.rotate(
              angle: math.pi / 4,
              child: Container(
                height: 100,
                width: 100,
                color: const Color(0xff565758),
                child: const Text("Lorem ipsum"),
              ),
            ),

Problem

Tried transform, transform.scale, FittedBox widgets. And the result is as in the picture above.

Solve:

Stack(
          children: [
            Transform.rotate(
              angle: math.pi / 4,
              child: Container(
                height: 100,
                width: 100,
                color: const Color(0xff565758),
              ),
            ),
            const Positioned.fill(child: Align(alignment: Alignment.center, child: Text("Lorem ipsum")))
          ],
        ),

>Solution :

you can use a stack to achieve this

Stack(
                alignment: Alignment.center,
                children: [
                  Transform.rotate(
                    angle: math.pi / 4,
                    child: Container(
                      height: 100,
                      width: 100,
                      color: const Color(0xff565758),
                      // child: const Text("Lorem ipsum"),
                    ),
                  ),
                  const Text("Lorem ipsum"),
                ],
              ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading