垂直居中文本,右对齐图像

姆瓦斯科

我正在为我的新Flutter应用开发SplashScreen。

这里有一个截图:

在此处输入图片说明

这是当前脚手架的代码:

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

我想更改第二个容器的布局。我想将图像放在图像的左侧,然后将文本放在图像的中心,垂直放置在图像的中心。

我一直在寻找解决方案几个小时,对于您的建议,我将不胜感激。

奥古斯特·基莫

这是您想要的吗?使用一行(我没有您的资产图片,因此我使用了一个蓝色容器)

在此处输入图片说明

将此代码复制/粘贴到www.dartpad.dev/flutter进行操作:

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),
          ),
        ]));
  }
}

您也可以使用crossAxisAlignment和/或mainAxisAlignment根据需要更改行的对齐方式

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章