【问题标题】:Flutter: How to make this scrollable [duplicate]Flutter:如何使这个可滚动[重复]
【发布时间】:2020-01-11 07:09:56
【问题描述】:

您好,这是我的第一个 Flutter 应用,我在让容器可滚动时遇到了一个小问题。

我想知道我需要添加什么才能使它成为可能?

    double c_width = MediaQuery.of(context).size.width;

return new Container (
  padding: const EdgeInsets.all(16.0),
  width: c_width,
  child: new Column (
    children: <Widget>[
            Row(
            children: <Widget>[
              new Text('DRN',style: TextStyle(color: Colors.black, fontSize: 20.0),),
               new Text('1', style: TextStyle(color: Colors.red, fontSize: 20.0),),
               new Text(': The Sound Of Indie',style: TextStyle(color: Colors.black, fontSize: 20.0),)

            ],
      ),
      Column (
        children: <Widget>[
          Padding(
            padding: EdgeInsets.all(8.0),
            child: Text ("When it comes to listening to music in this digital world there are so many ways to do it, either via YouTube, iTunes, Spotify, Google Music or the old fashioned Radio, where you get the commercial artists forced at you over and over again.", textAlign: TextAlign.left),
          ),
          Padding(
            padding: EdgeInsets.all(8.0),
            child: Text ("DRN1 is different. We are proud to show real talent, and artists that listeners may never of heard before but will quickly fall in love with. Sure, the music might not get publicised by major labels, and may not have the budget to get old styled radio stations playing. But, why should music come down to how much money you can throw at an artist just to hope that the listeners will end up buying said track or album?", textAlign: TextAlign.left),
          ),
      ],
      ),
      Row(
      children: <Widget>[
            new Text('The Sound of ',style: TextStyle(color: Colors.black, fontSize: 20.0),),
            new Text('Life', style: TextStyle(color: Colors.red, fontSize: 20.0),),

          ],
      ),
      Column (
          children: <Widget>[
            Padding(
             padding: EdgeInsets.all(8.0),
                  child: Text ("When it comes to listening to music in this digital world there are so many ways to do it, either via YouTube, iTunes, Spotify, Google Music or the old fashioned Radio, where you get the commercial artists forced at you over and over again.", textAlign: TextAlign.left),
      ),
              Padding(
                  padding: EdgeInsets.all(8.0),
                    child: Text ("DRN1 is different. We are proud to show real talent, and artists that listeners may never of heard before but will quickly fall in love with. Sure, the music might not get publicised by major labels, and may not have the budget to get old styled radio stations playing. But, why should music come down to how much money you can throw at an artist just to hope that the listeners will end up buying said track or album?", textAlign: TextAlign.left),
              ),
          ],
      ),
      Row(
        children: <Widget>[
          new Text('The Sound of ',style: TextStyle(color: Colors.black, fontSize: 20.0),),
          new Text('Life', style: TextStyle(color: Colors.red, fontSize: 20.0),),

        ],
      ),
      Column (
        children: <Widget>[
          Padding(
            padding: EdgeInsets.all(8.0),
            child: Text ("When it comes to listening to music in this digital world there are so many ways to do it, either via YouTube, iTunes, Spotify, Google Music or the old fashioned Radio, where you get the commercial artists forced at you over and over again.", textAlign: TextAlign.left),
          ),
          Padding(
            padding: EdgeInsets.all(8.0),
            child: Text ("DRN1 is different. We are proud to show real talent, and artists that listeners may never of heard before but will quickly fall in love with. Sure, the music might not get publicised by major labels, and may not have the budget to get old styled radio stations playing. But, why should music come down to how much money you can throw at an artist just to hope that the listeners will end up buying said track or album?", textAlign: TextAlign.left),
          ),
        ],
      ),

    ],
  ),
);

【问题讨论】:

    标签: flutter containers


    【解决方案1】:

    您可以将容器嵌套在 ListViewSingleChildScrollView

    【讨论】:

      【解决方案2】:

      您可以使用SingleChildScrollView 小部件:

      return new Container (
        padding: const EdgeInsets.all(16.0),
        width: c_width,
        child: new SingleChildScrollView(
          child: new Column (
            children: <Widget>[
                  Row(
                  children: <Widget>[
                    new Text('DRN',style: TextStyle(color: Colors.black, fontSize: 20.0),),
                     new Text('1', style: TextStyle(color: Colors.red, fontSize: 20.0),),
                     new Text(': The Sound Of Indie',style: TextStyle(color: Colors.black, fontSize: 20.0),)
      
                  ],
            ),
      ....
      

      您可以在以下链接中找到所有滚动小部件:

      https://flutter.dev/docs/development/ui/widgets/scrolling

      【讨论】:

        猜你喜欢
        • 2017-11-23
        • 1970-01-01
        • 2011-08-31
        • 2020-09-07
        • 2019-02-02
        • 2021-06-08
        • 2018-10-09
        • 2022-01-09
        • 2019-12-01
        相关资源
        最近更新 更多