Flutter中的Stack、Align、Positioned的使用

import 'package:flutter/material.dart';
import 'package:flutter_testdemo001/res/listData.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("flutter demo"),
        ),
        body: HomeContent(),
      ),
    );
  }
}

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // return Center(
    //   child: Stack(
    //     alignment: Alignment.center,
    //     children: <Widget>[
    //       Container(
    //         height: 400,
    //         width: 300,
    //         color: Colors.red,
    //       ),
    //       Text("我是一个文本", style: TextStyle(fontSize: 20, color: Colors.white))
    //     ],
    //   ),
    // );

    return Center(
      child: Container(
        height: 400,
        width: 300,
        color: Colors.red,
        child: Stack(
          children: <Widget>[
            Align(
              alignment: Alignment.topLeft,
              child: Icon(Icons.home,size:40,color: Colors.white),
            ),
            Align(
              alignment: Alignment.center,
              child: Icon(Icons.block,size:40,color: Colors.white),
            ),
            Align(
              alignment: Alignment.bottomRight,
              child: Icon(Icons.search,size:40,color: Colors.white),
            ),
          ],
        ),
      ),
    );
  }
}

 

posted @ 2019-10-23 09:56  生如逆旅,一苇以航  阅读(1774)  评论(0编辑  收藏  举报