[英]Positioning a widget on another widget flutter
You can use a Stack
with an overflow
property of Overflow.visible
and an alignment
of Alignemnt.center
, together with a Positioned
widget with negative bottom
value to achieve what you want.您可以使用
Stack
与overflow
的财产Overflow.visible
和alignment
的Alignemnt.center
,连同Positioned
与负小部件bottom
值来达到你想要什么。 Here is a snippet I wrote for you, I tried to imitate the image you shared.这是我为您写的片段,我试图模仿您分享的图像。 You can run it on DartPad if you need to manipulate the parameters or explore further.
如果您需要操作参数或进一步探索,您可以在 DartPad 上运行它。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Stack(
overflow: Overflow.visible,
alignment: Alignment.center,
children: <Widget>[
Container(
height: 150,
width: 300,
color: Colors.red
),
Positioned(
bottom: -50,
child: Container(
height: 100,
width: 150,
color: Colors.green
),
),
],
),
),
);
}
}
Here is what it looks like:这是它的样子:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.