Flutter开发笔记04 - Flutter_Widget布局控件笔记

 GitHub Demo 地址:https://github.com/LINGLemon/lxf_flutter_demo

1、Stack

Stack即层叠布局控件,能够将子控件层叠排列。Stack控件的每一个子控件都是定位或不定位,定位的子控件是被Positioned控件包裹的。Stack控件本身包含所有不定位的子控件,其根据alignment定位(默认为左上角)。然后根据定位的子控件的top、right、bottom和left属性将它们放置在Stack控件上。

import 'package:flutter/material.dart';
class StackDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("层叠布局"),
      ),
      body: new Center(
        child: new Stack(
          children: <Widget>[
            new Image.asset("images/hua3.png"),
            new Positioned(
                left:85.0,
              right: 35.0,
              top: 55.0,
              child:new Text(
                  "Hello World!",
                style: new TextStyle(
                  color: Colors.red,
                  fontSize: 20.0,
                  fontFamily: "serif"
                ),
            )
            )],
        ),
      ),
    );
  }
}
void main(){
  runApp(new MaterialApp(
    title: "层叠布局实例",
    theme: new ThemeData(primaryColor: Colors.deepOrange),
    home: new StackDemo(),
  ));
}

下图是使用stack实现一个带背景的appbar。

2、Scaffold

Scaffold 实现了基本的 Material 布局。只要是在 Material 中定义了的单个界面显示的布局控件元素,都可以使用 Scaffold 来绘制。

提供展示导航栏, 抽屉(drawers,比如:左边栏)、通知(snack bars) 以及 底部按钮(bottom sheets)。

我们可以将 Scaffold 理解为一个布局的容器。可以在这个容器中绘制我们的用户界面。

@override
Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
            title: new Text('应用'),
        ),
        body: new Center(
            child: new Text('Hello'),
        ),
    );
}

3、Expanded

只有一个子 Widget。在 Column 和 Row 中充满
Container只能根据里面容器大小来设置高度,而Expanded能够向下寻找可用的布局
import 'package:flutter/material.dart';

class Layout2Page extends StatefulWidget {
  @override
  _LayoutPage2State createState() => _LayoutPage2State();
}

class _LayoutPage2State extends State<Layout2Page> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('haha'),),
      body: Column(
        children: <Widget>[
          Text('列表'),
          Expanded(   // Container只能根据里面容器大小来设置高度,而Expanded能够向下寻找可用的布局
            child: Container(
              decoration: BoxDecoration(color: Colors.red),
              child: Text('竖直拉伸高度'),
            ),
          ),
        ],
      ),
    );
  }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值