0

我是颤振飞镖语言的新手,想知道如何使页面滚动。这是我要滚动的代码页面之一:

class Second extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DraggableScrollableSheet(
      builder: (context, scrollController) {
        return SingleChildScrollView(
          controller: scrollController,
          child: Scaffold(
            backgroundColor: const Color(0xffffffff),
            body: Stack(
              children: <Widget>[
                Transform.translate(
                  offset: Offset(30.0, 296.0),
                  child:
                    Container(
                      width: 315.0,
                      height: 287.0,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(37.0),
                        image: DecorationImage(
                          image: const AssetImage('assets/images/right.png'),
                          fit: BoxFit.fill,
                        )
                      ),
                    ),
                ),
              ],
            ),
          ),
        );
      }
    );
  }
}

请注意,这不是完整的代码,因为代码很长。我尝试使用 Draggable Scrollable Sheet,当我运行代码时,我只能看到一个黑屏。有人能帮我吗?提前致谢 :)

4

2 回答 2

0

在 Flutter 中进行滚动的最简单方法是使用 ListView 小部件。尝试这样的事情:

Widget build(BuildContext context) {
return Scaffold(
  body: ListView(
      children: [
        Column(
          children: [
            Container(
              height: 2000,
              child: Text('This container exceeds most screens'),
            ),
            Text('End of container.'),
          ],
        ),
      ],
    ),
  );
于 2020-09-10T17:13:14.483 回答
0

您可以使用 SingleChildScrollview 或 Listview 进行滚动,让我知道它是否适合您

  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: const Color(0xffffffff),
        appBar: AppBar(
          title: Text(""),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Stack(
                children: <Widget>[
                  Transform.translate(
                      offset: Offset(30.0, 296.0),
                      child: Container(
                        width: 315.0,
                        height: 287.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(37.0),
                            image: DecorationImage(
                               image: const                                                        
                               AssetImage('assets/images/right.png'),
                              fit: BoxFit.fill,
                            )),
                      )),
                ],
              ),
            ],
          ),
        ));
  }
于 2020-09-10T17:36:17.893 回答