Flutter - Container 组合类容器

在这里插入图片描述
它是DecoratedBox、ConstrainedBox、Transform、Padding、Align等组件组合的一个多功能容器,所以我们只需通过一个Container组件可以实现同时需要装饰、变换、限制的场景

示例
在这里插入图片描述

import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

class MyContainerState extends StatefulWidget {
  const MyContainerState({Key? key}) : super(key: key);

  
  State<MyContainerState> createState() => _MyState();
}

class _MyState extends State<MyContainerState> {
  
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("MyContainerState"),
      ),
      body: ConstrainedBox(
        constraints: const BoxConstraints.tightFor(width: double.infinity),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              constraints: const BoxConstraints.tightFor(width: double.infinity, height: 10),
              color: Colors.red,
            ),
            Container(
              constraints: const BoxConstraints.tightFor(width: double.infinity, height: 85),
              margin: const EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(5),
                  boxShadow: const [
                    BoxShadow(
                      color: Colors.black26,
                      offset: Offset(2, 2),
                      blurRadius: 3,
                    ),
                  ]),
              child: Row(
                children: <Widget>[
                  Expanded(
                    flex: 3,
                    child: Padding(
                        padding: const EdgeInsets.only(left : 10 ,right: 10,top: 8,bottom: 8),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Expanded(
                              flex: 10,
                              child: Padding(
                                  padding: const EdgeInsets.only(right: 0,top: 0,bottom:0),
                                  child: Text("中国工商业联合会第十三次全国代表大会开幕 李强代表中共中央国务院致贺词",
                                    maxLines: 2, // 最大行数
                                    overflow: TextOverflow.ellipsis,
                                      style:TextStyle( // 字体样式
                                        fontSize: 15.0 ,// 字体大小
                                        height:1.4 , // 行高系数  ,最后高度为  字体大小 * 行高系数
                                      )
                                  )
                              ),
                            ),
                            Spacer(
                              flex: 2,
                            ),
                            Expanded(
                              flex: 4,
                              child: Container(
                                constraints: const BoxConstraints.tightFor(width: double.infinity, height: double.infinity),
                                alignment: Alignment.centerLeft,
                                child: Row(
                                  children: <Widget>[
                                    Icon(Icons.access_time,size:13,color: Colors.grey,),
                                    Text("   2022-12-09",style: TextStyle(fontSize: 13,color: Colors.grey),)
                                  ],
                                ),
                              ),
                            ),
                          ],
                        )
                    ),
                  ),
                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.only(right: 10,top: 8,bottom: 8),
                      child: Image.network(
                        "https://i-blog.csdnimg.cn/blog_migrate/b98c7feebeb5115e991b7721ec073e9a.png",
                        width: double.infinity,
                        fit: BoxFit.fill,
                      )
                    ),
                  )
                ],

              ),
            ),
            Container(
              constraints: const BoxConstraints.tightFor(width: double.infinity, height: 10),
              color: Colors.red,
            ),
          ],
        ),
      ),
    );
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值