缺点:无法为每个组件单独定位
import 'package:flutter/material.dart';
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("首页"),
centerTitle: true,
),
body: HomeBody()
);
}
}
class HomeBody extends StatefulWidget {
@override
_HomeBodyState createState() => _HomeBodyState();
}
class _HomeBodyState extends State <HomeBody> {
@override
void initState() {
print("进入首页init");
super.initState();
}
@override
Widget build(BuildContext context) {
return Center(
child: Container(
width: 400,
height:400,
color: Colors.red,
child: Stack(
fit: StackFit.expand,
overflow: Overflow.visible,
alignment: Alignment(0,0),
children: [
Container(
width: 200,
height:200,
color: Color.fromRGBO(255, 0, 0, 0.3),
),
Text(
"这是一个文本",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
),
)
],
),
),
);
}
}