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),
            ),
          ],
        ),
      ),
    );
  }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM