flutter - 颤动中的堆栈是否存在屏幕问题
问题描述
我的问题是因为 我在屏幕顶部有一个图像,图像下方是身体脚手架的其余部分,但它有一个圆角
我使用了定位到appbar浮动和透明的堆栈,appbar下方的容器,但是我不能用这个堆栈做容器的圆角,这就是我正在做的
Scaffold(
body: Stack(
children: <Widget>[
SingleChildScrollView(
child: ...
)
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
...
),
),
],
),
)
试过这个之后,我不能用圆角做这个容器,我得到了这个
解决方案
您可以使用 Stack 和 Position 小部件来实现。
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: MyHomePage(),
));
class MyHomePage extends StatefulWidget {
@override
MyHomePageState createState() => MyHomePageState();
}
class MyHomePageState extends State<MyHomePage> {
final upperbodypartheight = 230;
final double rounded = 30;
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/crown.png"),
fit: BoxFit.cover,
),
),
height: 230,
child: AppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text("title"),
),
),
Positioned(
bottom: 0,
child: Container(
height: MediaQuery.of(context).size.height -
upperbodypartheight +
rounded,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.amber,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(rounded),
topRight: Radius.circular(rounded))),
),
),
],
);
}
}
推荐阅读
- postgresql - 致命:用户“postgres”的密码验证失败。无法连接
- html - 大写后的文本小写是可能的吗?
- django - 如何在投票系统的 Django 数据库中增加投票字段
- php - 如何在 Laravel 中更新数据库记录
- reactjs - 无法在反应 redux 项目的返回函数中使用查找函数
- c# - WPF 应用程序正在使用大量 GPU 功能
- design-patterns - 如何处理我的有效负载以在 cassandra 中具有原子性/一致性的多个表中插入批量数据?
- php - 三个 MySQL 表到一个主表的数据
- javascript - Javascript简单动画在移动设备上滞后
- vue.js - 在我的 vue js 代码中使用 composition-api 时出错?