flutter-container容器

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context){
    return MaterialApp(
      title: 'Text Widget',
      home: Scaffold(
        body: Center(
          child: Container(
            child: new Text('hello', style: TextStyle(fontSize: 40.0)),
            width: 500.0,
            height: 400.0,
            // color: Colors.blue,
            alignment: Alignment.topLeft,
            // padding: const EdgeInsets.all(10),
            padding: const EdgeInsets.fromLTRB(0.0, 20.0, 20.0, 30.0),
            margin: const EdgeInsets.all(20.0),
            decoration: new BoxDecoration(
              gradient: const LinearGradient(
                colors: [Colors.lightBlue, Colors.greenAccent, Colors.purple]
              ),
              border: Border.all(width: 2.0, color: Colors.red)
            ),
          ),
        )
      ),
    );
  }
}

color: Colors.lightBlue,容器的背景颜色。

EdgeInsets.fromLTRB(value1,value2,value3,value4) 可以满足我们的需求,LTRB分别代表左、上、右、下

decoration是 container 的修饰器,主要的功能是设置背景和边框。

比如你需要给背景加入一个渐变,这时候需要使用BoxDecoration这个类,代码如下(需要注意的是如果你设置了decoration,就不要再设置color属性了,因为这样会冲突)。

设置边框可以在decoration里设置border属性,比如代码中设置一个红色边框,宽度为2

posted @ 2020-09-15 17:24  江离白芷  阅读(222)  评论(0)    收藏  举报