//引入库
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)),
),
),
),
);
}
}
运行效果: