Flutter开发(三)—— Containery 控件

Container是Flutter中非常常用的控件,它是一个组合的widget,内部有绘制widget、定位widget、控制widget尺寸。

继承关系

Object > Diagnosticable > DiagnosticableTree > Widget > StatelessWidget > Container

下图是组合了一些常用属性,演示了一下简单用法。后附代码,并注释。
效果展示
在这里插入图片描述

上图代码:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,  //去掉AppBar右上角的debug图标
      title: "Hello",
      home: Scaffold(
        appBar: AppBar(title: Text("AppBar Hello")),
        body: Center(
          child: Container(
              alignment: Alignment.center, //控制 Center的child位置显示的
              child: new Text("Hello World!",
                  style: TextStyle(fontSize: 30, color: Colors.redAccent)),
              width: 400, //Container 宽度
              height: 300, //Container 高度

              // padding: const EdgeInsets.all(20), // padding 是Container内部填充,剩下的空间留给child  室内贴砖
              padding:
                  const EdgeInsets.fromLTRB(100, 50, 10, 100), //左上右下 设置各自距离

              // margin: const EdgeInsets.all(30),  // margin  是Container外部的边厚度,遇到它外边的容器自己缩小  外墙装修
              margin: const EdgeInsets.fromLTRB(30, 50, 10, 10),

              // color: Colors.lightBlue, //Container 背景颜色

              // BoxDecoration ——> LinearGradient 线性渐变
              decoration: new BoxDecoration(
                gradient: const LinearGradient(
                    colors: [Colors.lightGreen, Colors.orange, Colors.white10]),// 填充颜色 指定三种颜色
                border: Border.all(color: Colors.yellowAccent, width: 2.5,style: BorderStyle.solid),  //指定边框 颜色、宽度、样式
              ),
              transform: new Matrix4.rotationZ(0.3),  //Container旋转
              )
        ),
      ),
    );
  }
}


以上是Text 与 Containery配合使用,主要理解Containery的属性用法。
这里有一篇文章配图介绍了一部分属性的用法,如果你使搞过Android,应该可以极速理解。因为很多都是相同的,感觉没啥好记录的。也使因为属性太多,只能每个属性简单展示下,具体熟能生巧。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值