2

I want to align the text to the center inside the image as shown in the image. I recently started working with flutter please help me to achieve the layout. layout

Container(
            width: MediaQuery.of(context).size.width,
            margin: EdgeInsets.fromLTRB(24, 20, 24, 0),
            child: Stack(
              children: <Widget>[
                ClipRRect(
                  borderRadius: BorderRadius.circular(16.0),
                  child: Image.asset(
                    'assets/images/car.jpg',
                    fit: BoxFit.cover,
                  ),
                ),
                Positioned.fill(
                  child: Align(
                    alignment: Alignment.center,
                    child: Text(
                      'Cars',
                      style: TextStyle(
                          fontFamily: 'Welcome',
                          fontSize: 30,
                          color: Colors.white),
                    ),
                  ),
                )
              ],
            ),
          )

With the help of the above code, the text is appearing in the bottom-center instead of the center. layout

4
  • Your image link is broken. @Atul Chaudhary Commented Nov 5, 2019 at 10:46
  • @tyb9900 just change the links sry for the previously broken image links Commented Nov 5, 2019 at 10:51
  • you want the text in the center of the image ? Commented Nov 5, 2019 at 10:53
  • @tyb9900 yes, like the first image Commented Nov 5, 2019 at 11:01

3 Answers 3

1
    return Container(
      width: MediaQuery
          .of(context)
          .size
          .width,
      margin: EdgeInsets.fromLTRB(24, 20, 24, 0),
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          ClipRRect(
            borderRadius: BorderRadius.circular(16.0),
            child: Image.asset(
              Images.image1,
              fit: BoxFit.cover,
            ),
          ),
          Text(
            'Cars',
            style: TextStyle(
                fontFamily: 'Welcome',
                fontSize: 30,
                color: Colors.white),
          )
        ],
      ),
    );
Sign up to request clarification or add additional context in comments.

Comments

0
Container(
        width: MediaQuery
            .of(context)
            .size
            .width,
        margin: EdgeInsets.fromLTRB(24, 20, 24, 0),
        child: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            Container(
              decoration: BoxDecoration(
                ///For adding box Shadow
                boxShadow: [
                  BoxShadow(
                    color: Color(0xFF707070),
                    spreadRadius: 2,
                    blurRadius: 5,
                    offset: Offset(2, 3), // changes position of shadow
                  ),
                ],
                borderRadius: BorderRadius.circular(16),

              ),
              ///For image
              child: ClipRRect(
                 borderRadius: BorderRadius.circular(16),

                child: Image.asset(
                    'assets/images/car.png',
                  fit: BoxFit.cover,
                ),
              ),
            ),
            ///Text 
            Text(
              'Cars',
              style: TextStyle(
                  fontFamily: 'Urbanist',
                  fontSize: 30,
                  color: Colors.white),
            )
          ],
        ),

      ),

Comments

0

You can design this very easily with the code shown below. You can just add the Google font to style your text and change the image link and text according to your needs.

Center(
        child: Container(
          alignment: Alignment.center,
          height: MediaQuery.sizeOf(context).height * .2,
          width: MediaQuery.sizeOf(context).width * .7,
          decoration: BoxDecoration(
              color: Colors.blue,
              image: const DecorationImage(
                  image: NetworkImage(
                      'https://syska.co.in/blog/wp-content/uploads/2023/07/Syska_Smart_Lights.jpeg'),
                  fit: BoxFit.cover),
              borderRadius: BorderRadius.circular(25)),
          child:  Text(
            '3D',
            style: GoogleFonts.dancingScript(
          textStyle: Theme.of(context).textTheme.displayLarge,
          fontSize: 40,
          color: Colors.white,
          fontWeight: FontWeight.w900,
          fontStyle: FontStyle.italic,
        ),
          ),
        ),
      )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.