Kinda Code
Home/Flutter/Flutter: Display Text over Image without using Stack widget

Flutter: Display Text over Image without using Stack widget

Last updated: February 14, 2023

In Flutter, we can use the GridTile widget to display text over an image. This method is easier to implement but less customizable than using the Stack widget.

See also: Flutter: How to place Text over an Image with Stack

Example

Screenshot:

The code:

Scaffold(
      appBar: AppBar(
        title: const Text('KindaCode.com'),
      ),
      body: Center(
        child: SizedBox(
          width: double.infinity,
          height: 250,
          child: GridTile(
            footer: Container(
              // You can use GridTileBar instead
              width: double.infinity,
              padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
              color: Colors.black54,
              // You can use GridTileBar instead
              child: const Text(
                'This Is A Beautiful Photo',
                style: TextStyle(
                    color: Colors.white,
                    fontSize: 18,
                    fontWeight: FontWeight.bold),
                textAlign: TextAlign.right,
              ),
            ),
            child: Image.network(
                'https://www.kindacode.com/wp-content/uploads/2022/02/the-road.webp',
                width: double.infinity,
                height: 250,
                fit: BoxFit.cover),
          ),
        ),
      ),
);

You can find more exciting examples of the GridTile widget in this article.

Further reading:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.