dimanche 9 juillet 2023

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:

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")))
          ],
        ),

Aucun commentaire:

Enregistrer un commentaire