Flutter `Stack`不显示不在其第一个小部件区域内的内容

Flutter `Stack`不显示不在其第一个小部件区域内的内容,flutter,flutter-layout,Flutter,Flutter Layout,我试图在flutter中创建一个可滚动的用户界面。我添加了一个列表视图,然后在其中添加了一个堆栈 下面是我的代码 import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; var scaffoldKey = GlobalKey<ScaffoldState>(); class TestPage ext

我试图在flutter中创建一个可滚动的用户界面。我添加了一个
列表视图
,然后在其中添加了一个
堆栈

下面是我的代码

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:flutter/widgets.dart';

var scaffoldKey = GlobalKey<ScaffoldState>();

class TestPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      drawer: Drawer(
        child: ListView(
          // Important: Remove any padding from the ListView.
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text('Drawer Header'),
              decoration: BoxDecoration(
                color: Colors.blue,
              ),
            ),
            ListTile(
              title: Text('Item 1'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
      body: Container(
        height: double.infinity,
        child: ListView(
          shrinkWrap: true,
          children: <Widget>[TestPageUI()],
        ),
      ),
      key: scaffoldKey,
    );
  }
}

class TestPageUI extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return TestPageState();
  }
}

class TestPageState extends State<TestPageUI> {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Container(
          height: MediaQuery.of(context).size.height * .30,
          width: double.infinity,
          child: ClipPath(
            clipper: ClippingClass(),
            child: Container(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height * .30,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      fit: BoxFit.cover,
                      image: AssetImage("assets/images/morning_image.png"))),
            ),
          ),
        ),
        SafeArea(
          child: Row(
            children: <Widget>[
              IconButton(
                icon: Icon(
                  Icons.menu,
                  color: Colors.white,
                ),
                onPressed: () {
                  print("clicked");
                  scaffoldKey.currentState.openDrawer();
                },
              ),
              Spacer(
                flex: 2,
              ),
              IconButton(
                icon: Icon(
                  Icons.notifications,
                  color: Colors.white,
                ),
                onPressed: () {},
              ),
            ],
          ),
        ),
        Positioned(
          top: MediaQuery.of(context).size.height * .2,
          left: 0.0,
          right: 0.0,
          child: Align(
            alignment: Alignment.center,
            child: Container(
              child: Text(
                "Good Morning, Fred",
                style: Theme.of(context)
                    .textTheme
                    .headline
                    .apply(color: Colors.white),
              ),
            ),
          ),
        ),
        Positioned(
          top: MediaQuery.of(context).size.height * .3,
          left: 0.0,
          right: 0.0,
          child: Container(
            margin: EdgeInsets.only(left: 10, right: 10),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: MediaQuery.of(context).size.width * .22,
                  height: 100,
                  child: Column(
                    children: <Widget>[
                      Image.asset(
                        "assets/icons/car_service.png",
                        width: 48,
                        height: 48,
                      ),
                      Container(
                        margin: EdgeInsets.all(5),
                        child: Text(
                          "ONE",
                          style: Theme.of(context)
                              .textTheme
                              .caption
                              .apply(color: Colors.black),
                          textAlign: TextAlign.center,
                        ),
                      )
                    ],
                  ),
                ),
                Spacer(
                  flex: 1,
                ),
                Container(
                  width: MediaQuery.of(context).size.width * .22,
                  height: 100,
                  child: Column(
                    children: <Widget>[
                      Image.asset(
                        "assets/icons/car_service.png",
                        width: 48,
                        height: 48,
                      ),
                      Container(
                        margin: EdgeInsets.all(5),
                        child: Text(
                          "FOUR",
                          style: Theme.of(context)
                              .textTheme
                              .caption
                              .apply(color: Colors.black),
                          textAlign: TextAlign.center,
                        ),
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
        Positioned(
          top: MediaQuery.of(context).size.height * .54,
          left: 0.0,
          right: 0.0,
          child: Container(
            height: MediaQuery.of(context).size.height,
            child: ListView.builder(
              itemCount: 100,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  margin: EdgeInsets.only(bottom: 10, left: 10, right: 10),
                  child: _createAdvertisement(),
                );
              },
            ),
          ),
        )
      ],
    );
  }

  Widget _createAdvertisement() {
    return Card(
      elevation: 4.0,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
      clipBehavior: Clip.antiAlias,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          FadeInImage.assetNetwork(
            alignment: Alignment.topCenter,
            placeholder: "https://picsum.photos/200",
            image: "https://picsum.photos/200",
            fit: BoxFit.fill,
            width: double.infinity,
            height: MediaQuery.of(context).size.height * .9 / 4,
          ),
          
          
        ],
      ),
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
}

class ClippingClass extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    var path = Path();
    path.lineTo(0.0, size.height);
    path.quadraticBezierTo(
        size.width / 4, size.height - 30, size.width / 2, size.height - 30);
    path.quadraticBezierTo(size.width - (size.width / 4), size.height - 30,
        size.width, size.height);
    path.lineTo(size.width, 0.0);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
import'包装:flift/cupertino.dart';
进口“包装:颤振/材料.省道”;
导入“package:flatter/widgets.dart”;
var scaffoldKey=GlobalKey();
类TestPage扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.white,
抽屉(
子:ListView(
//重要提示:从ListView中删除任何填充。
填充:EdgeInsets.zero,
儿童:[
抽屉阅读器(
子项:文本(“抽屉标题”),
装饰:盒子装饰(
颜色:颜色,蓝色,
),
),
列表砖(
标题:文本(“项目1”),
onTap:(){
//更新应用程序的状态
// ...
//然后关上抽屉
Navigator.pop(上下文);
},
),
列表砖(
标题:文本(“项目2”),
onTap:(){
//更新应用程序的状态
// ...
//然后关上抽屉
Navigator.pop(上下文);
},
),
],
),
),
主体:容器(
高度:双无限,
子:ListView(
收缩膜:对,
子项:[TestPageUI()],
),
),
钥匙:脚手架钥匙,
);
}
}
类TestPageUI扩展StatefulWidget{
@凌驾
状态createState(){
//TODO:实现createState
返回TestPageState();
}
}
类TestPageState扩展了状态{
@凌驾
小部件构建(构建上下文){
返回堆栈(
儿童:[
容器(
高度:MediaQuery.of(context).size.height*.30,
宽度:double.infinity,
孩子:克利帕斯(
裁剪器:裁剪类(),
子:容器(
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height*.30,
装饰:盒子装饰(
图像:装饰图像(
适合:BoxFit.cover,
图片:AssetImage(“assets/images/morning_image.png”),
),
),
),
安全区(
孩子:排(
儿童:[
图标按钮(
图标:图标(
图标菜单,
颜色:颜色,白色,
),
已按下:(){
打印(“点击”);
scaffoldKey.currentState.openDrawer();
},
),
间隔棒(
弹性:2,
),
图标按钮(
图标:图标(
图标、通知、,
颜色:颜色,白色,
),
按下:(){},
),
],
),
),
定位(
顶部:MediaQuery.of(context).size.height*.2,
左:0.0,
右:0.0,
子对象:对齐(
对齐:对齐.center,
子:容器(
子:文本(
“早上好,弗雷德”,
风格:主题(上下文)
.文本主题
大字标题
.应用(颜色:颜色。白色),
),
),
),
),
定位(
顶部:MediaQuery.of(context).size.height*.3,
左:0.0,
右:0.0,
子:容器(
边距:仅限边集(左:10,右:10),
孩子:排(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
宽度:MediaQuery.of(context).size.width*.22,
身高:100,
子:列(
儿童:[
影像资产(
“资产/图标/汽车服务.png”,
宽度:48,
身高:48,
),
容器(
保证金:所有(5),
子:文本(
“一个”,
风格:主题(上下文)
.文本主题
说明文字
.应用(颜色:颜色。黑色),
textAlign:textAlign.center,
),
)
],
),
),
间隔棒(
弹性:1,
),
容器(
宽度:MediaQuery.of(context).size.width*.22,
身高:100,
子:列(
儿童:[
影像资产(
“资产/图标/汽车服务.png”,
宽度:48,
身高:48,
),
容器(
保证金:所有(5),
子:文本(
“四”,
风格:主题(上下文)
.文本主题
说明文字
.应用(颜色:颜色。黑色),
textAlign:textAlign.center,
),
)
],
),
),
],
),
),
),
定位(
顶部:MediaQuery.of(context).size.height*.54,
左:0.0,
右:0.0,
Stack(overflow: Overflow.visible,
      child:.....)