Flutter 浅析之 Container容器

17 篇文章 0 订阅
12 篇文章 2 订阅

技术无止境,只怕不学习啊,Flutter我们开始吧

Flutter Container容器
在Container容器添加Text文本以及字体大写

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            child: Text(
              "Hello xinge", // 文字内容
              style: TextStyle(fontSize: 40.0), // 字体样式 字体大小
            ),
          ),
        ),
      ),
    );
  }
}

在这里插入图片描述
Alignment子空间的对齐方式

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            child: Text(
              "Hello xinge", // 文字内容
              style: TextStyle(fontSize: 40.0), // 字体样式 字体大小
            ),
            alignment: Alignment.topLeft, // 字内容的对齐方式 center居中,centerLeft居中左侧 centerRight居中右侧
            // bottomCenter 下居中对齐 ,bottomLeft 下左对齐,bottomRight 下右对齐
            // topCenter 上居中对齐,topLeft 上左对齐,topRight 上右对齐
          ),
        ),
      ),
    );
  }
}

在这里插入图片描述

Container容器的高度宽度 以及背景色

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            child: Text(
              "Hello xinge", // 文字内容
              style: TextStyle(fontSize: 40.0), // 字体样式 字体大小
            ),
            alignment: Alignment.topLeft, // 字内容的对齐方式 center居中,centerLeft居中左侧 centerRight居中右侧
            // bottomCenter 下居中对齐 ,bottomLeft 下左对齐,bottomRight 下右对齐
            // topCenter 上居中对齐,topLeft 上左对齐,topRight 上右对齐
            width: 500,   // 宽
            height: 400,  // 高
            color: Colors.red, //颜色   color和decoration不可以同时存在
          ),
        ),
      ),
    );
  }
}

在这里插入图片描述

Container内边距 padding

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            child: Text(
              "Hello xinge", // 文字内容
              style: TextStyle(fontSize: 40.0), // 字体样式 字体大小
            ),
            alignment: Alignment.topLeft, // 字内容的对齐方式 center居中,centerLeft居中左侧 centerRight居中右侧
            // bottomCenter 下居中对齐 ,bottomLeft 下左对齐,bottomRight 下右对齐
            // topCenter 上居中对齐,topLeft 上左对齐,topRight 上右对齐
            width: 500,   // 宽
            height: 400,  // 高
            color: Colors.red, //颜色   color和decoration不可以同时存在
            padding: const EdgeInsets.fromLTRB(20.0,20.0,20.0,20.0), // 边距 all 包括上下左右  fromLTRB 上下左右分别设置边距fromLTRB(20.0,20.0,20.0,20.0)
          ),
        ),
      ),
    );
  }
}

在这里插入图片描述
Container外边距margin

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            child: Text(
              "Hello xinge", // 文字内容
              style: TextStyle(fontSize: 40.0), // 字体样式 字体大小
            ),
            alignment: Alignment.topLeft, // 字内容的对齐方式 center居中,centerLeft居中左侧 centerRight居中右侧
            // bottomCenter 下居中对齐 ,bottomLeft 下左对齐,bottomRight 下右对齐
            // topCenter 上居中对齐,topLeft 上左对齐,topRight 上右对齐
            width: 500,   // 宽
            height: 400,  // 高
            color: Colors.red, //颜色   color和decoration不可以同时存在
            padding: const EdgeInsets.fromLTRB(20.0,20.0,20.0,20.0), // 边距 all 包括上下左右  fromLTRB 上下左右分别设置边距fromLTRB(20.0,20.0,20.0,20.0)
            margin: const EdgeInsets.all(30.0), // 外间距
          ),
        ),
      ),
    );
  }

在这里插入图片描述

Container渐变色decoration

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            child: Text(
              "Hello xinge", // 文字内容
              style: TextStyle(fontSize: 40.0), // 字体样式 字体大小
            ),
            alignment: Alignment.topLeft, // 字内容的对齐方式 center居中,centerLeft居中左侧 centerRight居中右侧
            // bottomCenter 下居中对齐 ,bottomLeft 下左对齐,bottomRight 下右对齐
            // topCenter 上居中对齐,topLeft 上左对齐,topRight 上右对齐
            width: 500,   // 宽
            height: 400,  // 高
//            color: Colors.red, //颜色   color和decoration不可以同时存在
            padding: const EdgeInsets.fromLTRB(20.0,20.0,20.0,20.0), // 边距 all 包括上下左右  fromLTRB 上下左右分别设置边距fromLTRB(20.0,20.0,20.0,20.0)
            margin: const EdgeInsets.all(30.0), // 外间距
            decoration: new BoxDecoration( // 渐变
              gradient: const LinearGradient(
                  colors:
                  [Colors.lightBlue,Colors.greenAccent,Colors.purple],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

在这里插入图片描述
Container边框border

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            child: Text(
              "Hello xinge", // 文字内容
              style: TextStyle(fontSize: 40.0), // 字体样式 字体大小
            ),
            alignment: Alignment.topLeft, // 字内容的对齐方式 center居中,centerLeft居中左侧 centerRight居中右侧
            // bottomCenter 下居中对齐 ,bottomLeft 下左对齐,bottomRight 下右对齐
            // topCenter 上居中对齐,topLeft 上左对齐,topRight 上右对齐
            width: 500,   // 宽
            height: 400,  // 高
//            color: Colors.red, //颜色   color和decoration不可以同时存在
            padding: const EdgeInsets.fromLTRB(20.0,20.0,20.0,20.0), // 边距 all 包括上下左右  fromLTRB 上下左右分别设置边距fromLTRB(20.0,20.0,20.0,20.0)
            margin: const EdgeInsets.all(30.0), // 外间距
            decoration: new BoxDecoration( // 渐变
              gradient: const LinearGradient(
                  colors:
                  [Colors.lightBlue,Colors.greenAccent,Colors.purple],
              ),
              border: Border.all(width: 5.0,color: Colors.red),  // 边框
            ),
          ),
        ),
      ),
    );
  }
}

在这里插入图片描述

Container 到此为止,其他的大家可以自行查询API

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值