Flutter教学

Flutter(44):Layout组件之Container

2020-10-10  本文已影响0人  starryxp

Flutter教学目录持续更新中

Github源代码持续更新中

1.Container介绍

2.Container属性

3.Alignment属性

body: Container(
  color: Colors.amber,
  alignment: Alignment.lerp(Alignment.topLeft, Alignment.bottomRight, 0.25),
  child: Container(
    width: 50,
    height: 50,
    color: Colors.blue,
  ),
),

4.BoxDecoration属性

1602323434(1).png
body: Container(
  color: Colors.amber,
  alignment: Alignment.center,
  /*Alignment.lerp(Alignment.topLeft, Alignment.bottomRight, 0.25)*/
  child: Container(
    width: 300,
    height: 300,
    // color: Colors.blue,
    decoration: BoxDecoration(
      // color: Colors.blue,
      image: DecorationImage(
          image: NetworkImage(_imageUrl), fit: BoxFit.fill),
      borderRadius: BorderRadius.circular(10),
      // shape: BoxShape.circle,
      boxShadow: [
        BoxShadow(
          offset: Offset(2, 1), //x,y轴
          color: Colors.grey, //投影颜色
          blurRadius: 3,
          spreadRadius: 3, //投影距离
        )
      ],
    ),
     foregroundDecoration: BoxDecoration(
       color: Color(0x55ffffff),
       shape: BoxShape.circle,
     ),
  ),
),

5.constraints

6.最后我们来讲讲Container自身尺寸的调节的问题

Container作为整个试图根节点

Container作为子节点

Container的大小不会超越父节点大小

Container不设置child
Container设置child

下一节:Layout组件之Padding

Flutter(45):Layout组件之Padding

Flutter教学目录持续更新中

Github源代码持续更新中

上一篇下一篇

猜你喜欢

热点阅读