Vertical centered text and right aligned to an image

1

I am working on a SplashScreen for my new Flutter app.

Here you have a screenshot of it:

enter image description here

And here you have the code for the current Scaffold:

return Scaffold(
      body: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage("assets/splash/${yourList[randomIndex]}"),
                fit: BoxFit.cover,
              ),
            ),
//        child: [Your content here],
          ),
          Container(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height * 0.1,
              decoration: new BoxDecoration(
                color: const Color(0xFFFFFFFF).withOpacity(0.5),
                image: DecorationImage(
                  image: new AssetImage('assets/images/app_icon_trans.png'),
                ),
              ),
              child: Text(
                "© 2020 Mov-Map version: ${_projectVersion}",
                style: TextStyle(
                    color: Colors.red,
                    fontWeight: FontWeight.bold,
                    fontSize: 16.0),
              ))
        ],
      ),
    );

I would like to change the layout for the second container. I would like to put the image on the left side and the text just after the image, vertically at the center of the image.

I have been searching for a solution for a couple of hours and I would appreciate your proposals.

flutter
asked on Stack Overflow Dec 7, 2020 by mvasco • edited Dec 7, 2020 by Akif

1 Answer

2

Is this how you would like it? Use a row (I don't have your asset image, so I used a blue container instead)

enter image description here

Copy/paste this code into www.dartpad.dev/flutter to play with it:

import 'package:flutter/material.dart';

final Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height * 0.1,
        decoration:
            new BoxDecoration(color: const Color(0xFFFFFFFF).withOpacity(0.5)),
        child: Row(children: [
          Container(
            width: 40,
            height: 40,
            color: Colors.blue,
          ),
          Text(
            "© 2020 Mov-Map version: 1",
            style: TextStyle(
                color: Colors.red, fontWeight: FontWeight.bold, fontSize: 16.0),
          ),
        ]));
  }
}

You can also change the Row's alignment using crossAxisAlignment and/or mainAxisAlignment if needed.

answered on Stack Overflow Dec 7, 2020 by August Kimo

User contributions licensed under CC BY-SA 3.0