【问题标题】:Flutter page is not scrollable: How to scroll when more than one widget?Flutter页面不可滚动:多个小部件时如何滚动?
【发布时间】:2021-09-11 02:46:59
【问题描述】:

我正在尝试使我的页面可滚动,但我没有管理它。到目前为止,我尝试的是使用 SingeChildScrollViewListViewScrollView... 每次我使用其中之一时,都会发生错误。我该如何管理? 有没有其他方法可以使用这三个选项? 我是 Flutter 的新手,到目前为止我用谷歌搜索的内容没有用,因为我只能找到这三个滚动选项之一的解决方案。 谢谢! 这是我的代码:


class LadevorgangScreen extends StatefulWidget {
  @override
  _LadevorgangScreen createState() => _LadevorgangScreen();
}

@override
class _LadevorgangScreen extends State<LadevorgangScreen> {
//class LadevorgangScreen extends StatelessWidget {

  PageController pageController = PageController(initialPage: 0);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Ladevorgang'),
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
                colors: [Color(0xffFBD23E), Color(0xffF6BE03)],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter),
          ),
        ),
      ),
      body: Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
              colors: [Color(0xffFEFDFD), Color(0xffBDBDB2)],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight),
        ),
        child: Column(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.fromLTRB(10, 15, 10, 45),
              child: FlatButton(
                onPressed: () {},
                color: Colors.blue,
                highlightColor: Colors.transparent,
                splashColor: Colors.transparent,
                child: RichText(
                  textAlign: TextAlign.center,
                  text: TextSpan(
                    text: 'FAQs:\n',
                    style: TextStyle(
                      fontFamily: 'Avenir',
                      fontSize: 22.0,
                      fontWeight: FontWeight.w900,
                      decoration: TextDecoration.underline,
                      color: Color(0xff232323),
                    ),
                    children: [
                      TextSpan(
                        text: 'Ladevorgang des Elektroautos',
                        style: TextStyle(
                            fontFamily: 'Avenir',
                            fontSize: 20.0,
                            fontWeight: FontWeight.w500,
                            decoration: TextDecoration.none,
                            color: Color(0xff232323)),
                      ),
                    ],
                  ),
                ),
              ),
            ),
            Flexible(
              child: Text(
                'Zu Hause laden',
                style: TextStyle(
                    fontSize: 18.5,
                    fontFamily: 'Avenir',
                    fontWeight: FontWeight.w700),
              ),
            ),
            Padding(
              padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
              child: Column(
                children: [
                  Row(
                    children: [
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 12, 7, 12),
                        child: Icon(
                          Icons.circle_outlined,
                          size: 15.0,
                          color: Color(0xffF6BE03),
                        ),
                      ),
                      Flexible(
                        child: Text(
                          "Wie lade ich zu Hause?",
                          style:
                              TextStyle(fontSize: 17.0, fontFamily: 'Avenir'),
                        ),
                      ),
                    ],
                  ),
                  Row(
                    children: [
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 12, 7, 12),
                        child: Icon(
                          Icons.circle_outlined,
                          size: 15.0,
                          color: Color(0xffF6BE03),
                        ),
                      ),
                      Flexible(
                        child: Text(
                            "Benötige ich überhaupt eine Lademöglichkeit zu Hause?",
                            style: TextStyle(
                                fontSize: 17.0, fontFamily: 'Avenir')),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

【问题讨论】:

  • 你得到什么错误?

标签: ios flutter dart scroll uiscrollview


【解决方案1】:

只需将您的主要小部件 OF BODY 包裹在 SingleChildScrollView 小部件中

   body: SingleChildScrollView(
    child: Container(
      decoration: BoxDecoration
       .....
       ..
       .

【讨论】:

  • 您只需将您的小部件包装在 SingleChildScrollView 小部件的正文中。
  • 感谢您的回复 Muhammad Tameem Rafay,但我已经尝试过,就像您描述的那样。它不起作用..
  • 不知何故我设法做到了。不管怎样,谢谢你! :)
猜你喜欢
  • 2019-07-16
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多