flutter - 如何在颤动中将容器堆叠在另一个容器内部或下方
问题描述
import 'package:flutter/material.dart';
void main() {
runApp(MainScreen());
}
class MainScreen extends StatelessWidget {
const MainScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return Scaffold(
body: Column(
children: <Widget>[
Stack(
children: [
Container(
height: 250.0,
width: width,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(150),
bottomRight: Radius.circular(150),
),
color: Colors.redAccent,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Hello World",
style: TextStyle(
fontSize: 22,
fontFamily: "Arial",
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text(
"Hello World",
style: TextStyle(
fontSize: 22,
fontFamily: "Arial",
fontWeight: FontWeight.bold,
color: Colors.white),
),
],
),
),
),
],
),
Stack(
children: [
Positioned(
top: 40,
left: 20,
child: Container(
height: 500,
width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.grey,
),
),
),
],
),
],
),
);
}
}
我试图添加一个基于同一行的新容器,但找不到如何与另一个容器堆叠,第二个容器使用定位小部件,但没有奏效。毕竟使用堆栈使第一个容器与第二个容器相同,并且定位的小部件仍然没有解决
我试图添加一个基于同一行的新容器,但找不到如何与另一个容器堆叠,第二个容器使用定位小部件,但没有奏效。毕竟使用堆栈使第一个容器与第二个容器相同,并且定位的小部件仍然没有解决
我上传了一张图片,其中包含两个容器,但没有堆叠在底部。谢谢你。
解决方案
如果要将两个容器放入堆栈,则不需要创建两个堆栈。您只需将两个容器放在一个堆栈中,然后用定位包装其中一个。像这样:
import 'package:flutter/material.dart';
void main() {
runApp(MainScreen());
}
class MainScreen extends StatelessWidget {
const MainScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return Scaffold(
body: Stack(
children: [
Container(
height: 250.0,
width: width,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(150),
bottomRight: Radius.circular(150),
),
color: Colors.redAccent,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Hello World",
style: TextStyle(
fontSize: 22,
fontFamily: "Arial",
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text(
"Hello World",
style: TextStyle(
fontSize: 22,
fontFamily: "Arial",
fontWeight: FontWeight.bold,
color: Colors.white),
),
],
),
),
),
Positioned(
top: 40,
left: 20,
child: Container(
height: 500,
width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.grey,
),
),
),
],
),
);
}
}
推荐阅读
- php - 如何运行长循环需要超过允许的最大执行时间
- angular - dialogref.afterclosed() 结果为空 Angular 8
- objective-c - UIScrollView:我可以将手指滚动运动从一个滚动视图重定向到另一个滚动视图吗?
- javascript - 在显示 HTML 之前检查 JS 值是否存在
- powerbi - Power BI 数据集(或几列)到 Power Apps
- python - keras 中的自定义损失在自编码器的训练过程中会产生误导性的输出
- sql - SQL - 来自同一个表的多个值(多对一)
- javascript - 带有 SPA 应用程序和 API 的会话
- c# - 如何实现控制任务
- ios - 无法使用类型为“(格式:字符串,双精度)”的参数列表调用类型“Int”的初始化程序