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()
              ],
            )
相关推荐
恋猫de小郭14 小时前
你还用 IDE 吗? AI 狂欢时代下 Cursor 慌了, JetBrains 等 IDE 的未来是什么?
前端·flutter·ai编程
TT_Close1 天前
🐟 发布中心进度同步:8 个商店的上传功能开发完毕,正抓紧测试
flutter·npm·visual studio code
RaidenLiu1 天前
Flutter Platform Channel 底层架构解析 —— 从 BinaryMessenger 到跨平台消息通信机制
前端·flutter·前端框架
鹏多多2 天前
Flutter使用screenshot进行截屏和截长图以及分享保存的全流程指南
android·前端·flutter
恋猫de小郭2 天前
什么 AI 写 Android 最好用?官方做了一个基准测试排名
android·前端·flutter
勤劳打代码3 天前
Flutter 架构日记 — 状态管理
flutter·架构·前端框架
比特鹰4 天前
手把手带你用Flutter手搓人生K线
前端·javascript·flutter
火柴就是我4 天前
Flutter限制输入框只能输入中文,iOS拼音打不出来?
flutter
TT_Close4 天前
【Flutter×鸿蒙】debug 包也要签名,这点和 Android 差远了
android·flutter·harmonyos
TT_Close5 天前
【Flutter×鸿蒙】FVM 不认鸿蒙 SDK?4步手动塞进去
flutter·swift·harmonyos