Flutter学习-Container组件

//引入库
import 'package:flutter/material.dart';

//主函数
void main() => runApp(myApp());

//类,继承无状态组件
class myApp extends StatelessWidget {
  //重写函数
  @override
  //返回值为Widget类型
  Widget build(BuildContext context) {
    //对应函数类型返回值
    return MaterialApp(
      //dart结构,title和home
      title: 'flutter study',
      //home,故用脚手架
      home: Scaffold(
        //顶上一个appBar
        appBar: AppBar(
          title: Text('welcome to flutter'),
        ),
        //中间是身体
        body: Center(
          //容器
          child: Container(
            //子组件
            child: new Text('Hello World!', style: TextStyle(fontSize: 40.0)),
            //对齐
            alignment: Alignment.topLeft, //topLeft, bottomRight等
//            color: Colors.yellow, //颜色
            height: 200.0, //高度,浮点型
            width: 500.0, //宽度,浮点型
            //内边距
            padding:
                const EdgeInsets.fromLTRB(10.0, 20.0, 30.0, 40.0), //左上右下,常量
            //外边距,无视容器宽度,强制设定与屏幕的距离
            margin: const EdgeInsets.all(30.0), //全,常量
            //修饰,new出组件,与上边color属性不能同时出现
            decoration: new BoxDecoration(
                //颜色渐变
                gradient: LinearGradient(//线性渐变
                    colors: [Colors.yellow, Colors.red, Colors.blue]),
                //边界
                border: Border.all(width: 6.0, color: Colors.black)),
          ),
        ),
      ),
    );
  }
}

运行效果:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值