flutter实战之美化 container

我们来看一个代码

Dart 复制代码
Column(
              children: [
                ...transaction.map((e) => Card(
                  child:Row(
                    children: [
                      Container(child: Text(e.amout.toString()),),
                      Column(
                        children: [
                          Text(e.title),
                          Text(e.date.toString()),
                        ],
                      )
                    ],
                  ),
                )).toList()
              ],
            )

看看效果

感觉很不好

我们要去美化一下container

  • symmetric({vertical, horizontal}):用于设置对称方向的填充,vertical指top和bottom,horizontal指left和right。

另外,首先我们要了解可以通过container来设置边距和边框,可以在Textstytle中来设置美化样式,对于Column 中可以设置对称轴的对齐方式

我们来看看代码

Dart 复制代码
Column(
              children: [
                ...transaction
                    .map((e) => Card(
                          child: Row(
                            children: [
                              Container(
                                padding: EdgeInsets.all(10),
                                child: Text(
                                  e.amout.toString(),
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 16,
                                      color: Colors.purple),
                                ),
                                margin: EdgeInsets.symmetric(
                                    vertical: 10, horizontal: 15),
                                decoration: BoxDecoration(
                                    border: Border.all(
                                        color: Colors.purple, width: 2)),
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(e.title,
                                  style: TextStyle(
                                    fontSize: 10,
                                    color: Colors.grey
                                  ),),
                                  Text(e.date.toString()),
                                ],
                              )

效果如下:

对于价钱的格式我们可以借助

Dart 复制代码
Text(
                                  "\$${e.amout}",
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 16,
                                      color: Colors.purple),
                                ),

来实现相同的效果

我们看看最后的美化代码

Dart 复制代码
Column(
              children: [
                ...transaction
                    .map((e) => Card(
                          child: Row(
                            children: [
                              Container(
                                padding: EdgeInsets.all(10),
                                child: Text(
                                  "\$${e.amout}",
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 16,
                                      color: Colors.purple),
                                ),
                                margin: EdgeInsets.symmetric(
                                    vertical: 10, horizontal: 15),
                                decoration: BoxDecoration(
                                    border: Border.all(
                                        color: Colors.purple, width: 2)),
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    e.title,
                                    style: TextStyle(
                                        fontSize: 10, color: Colors.grey),
                                  ),
                                  Text(DateFormat().format(e.date)),
                                ],
                              )
                            ],
                          ),
                        ))
                    .toList()
              ],
            )
相关推荐
stringwu7 小时前
Flutter 开发者必备:WebSocket 实用指南
flutter
小林的技术分享7 小时前
关于排查 Flutter 3.27.0 版本Android端无法禁用Impeller引擎的过程记录
前端·flutter
coder_pig1 天前
🤡 公司Android老项目升级踩坑小记
android·flutter·gradle
w_y_fan1 天前
双token机制:flutter_secure_storage 实现加密存储
前端·flutter
dragon7251 天前
关于image组件设置宽高不生效问题的探究
flutter
会煮咖啡的猫1 天前
Flutter 是否需要 UI 组件库?
flutter
眼镜会飞1 天前
Flutter 3.x新版android端的build.gradle.kts文件配置arm64-v8a和armeabi-v7a等
android·前端·flutter
恋猫de小郭1 天前
Flutter 小技巧之有趣的 UI 骨架屏框架 skeletonizer
android·前端·flutter
一狐九1 天前
Flutter如何通过GlobalKey调用组件内的方法
前端·flutter
张风捷特烈1 天前
鸿蒙纪·Flutter卷#03 | 从配置证书到打包发布
android·flutter·harmonyos