## Container组件
容器组件,类似于div,用于布局
**decoration属性,背景颜色,边框颜色属性等**
1. child
2. height(double):高度
3. width:宽度
4. padding(EdgeInsets):内边距 fromLTRB(左,上,右,下)
5. margin:同padding
6. alignment(Alignment):child在容器中的对齐方式
7. transform(Matrix4):动画 translationValues rotationZ
9. decoration(BoxDecoration):背景颜色,边框,圆角
* color(Color, Colors):背景颜色,
* border(Border):边框
同时设置四条边框
~~~
Border.all(
width: 2.0//边框宽度
color: Colors.pink//边框颜色,
style: BorderStyle.solid//只支持实线
)
~~~
设置单边框
~~~
border: Border(
left: BorderSide(
color: Colors.black,
width:2.0,
),
right: BorderSide(
color: Colors.blue,
width:4.0,
),
),
~~~
* borderRadius:圆角
写法一:
~~~
borderRadius: BorderRadius.all(
Radius.circular(20),
),
~~~
写法二:
~~~
BorderRadius.circular(40)
~~~
不规则:
写法一
~~~
borderRadius: BorderRadius.vertical(
top: Radius.elliptical(50, 50),
bottom: Radius.elliptical(50, 50)
),
~~~
写法二:
~~~
borderRadius: BorderRadius.horizontal(
left: Radius.elliptical(40, 40),
right: Radius.elliptical(50, 50)
),
~~~
~~~
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Flutter demo'),
),
body: HomeContent()
)
);
}
}
class HomeContent extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return Center(
child: Container(
child: Text(
'我是一个文本',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 16.0,
color: Color.fromRGBO(155, 111, 111, 1),
fontWeight: FontWeight.w800,
fontStyle: FontStyle.italic,
decoration: TextDecoration.lineThrough,//文字装饰
decorationColor: Colors.white,
decorationStyle: TextDecorationStyle.dashed,
letterSpacing: 5.0 //字间距
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
textScaleFactor: 1.5,//设置字体缩放
),
height: 300.0,
width: 300.0,
//decoration属性,背景颜色,边框颜色 宽度属性等
decoration: BoxDecoration(
color: Colors.yellow,
border: Border.all(
color: Colors.blue,
width: 4.0,
),
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
//EdgeInsets.all(10.0),
padding: EdgeInsets.fromLTRB(10, 30, 10, 10),
// transform: Matrix4.translationValues(10.0, 10.0, 0),
// transform: Matrix4.rotationZ(-0.3),
alignment: Alignment.bottomRight,//元素显示位置
),
);
}
}
~~~
- 空白目录
- Flutter入门
- 课程简介
- 开发环境搭建
- 常用组件讲解
- 案例实战
- Dart编程语言入门
- 介绍和开发准备
- 数据类型
- 运算符
- 控制流语句
- 方法
- 面向对象1
- 面向对象2
- 枚举&类型
- Flutter中文网
- Widget框架总览
- 在Flutter中构建布局
- Flutter for Web开发者
- Flutter入门实战
- flutter介绍
- Flutter目录结构,各种组件
- Container、Text
- 图片组件Image
- ListView
- 动态组件
- GridView组件
- 页面布局Padding,Row,Column,Expanded,Icon
- Stack层叠组件,Align,Positioned
- AspectRatio,Cart
- wrap组件
- 组件汇总
