使用“文本”小部件和Marquee flutter插件为水平视口赋予了无限的宽度

时间:2020-06-28 01:33:52

标签: flutter dart marquee

我正在尝试建立列表视图,并且在其中具有用于YouTube的标题文本,并且该文本很长,我正试图使用​​Marquee。但它一直使我处于错误之下,我尝试添加收缩包装,但未能解决问题。我还注意到许多人报告了身高相似的问题,但是这些人提供的解决方案并没有帮助我。

enter image description here enter image description here

child: ListView.builder(
       itemCount: ytResult.length,
       shrinkWrap: true,
       itemBuilder: (_, int index) => listsongs(index),                
),

--------------------------------- list歌曲小部件------------ ------------

Widget listsongs(index){
    return Container(
      margin: EdgeInsets.only(bottom: 10),
      child: Column(
        children: <Widget>[
          Container(
            height: 200,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: NetworkImage(ytResult[index].thumbnail['high']['url']),
                fit: BoxFit.fill,
              ),
          ),
          ),
          Container(
            margin: EdgeInsets.only(left: 10, top: 10, bottom: 10),
            child: Row(              
              children: <Widget> [

                Container(
                  margin: EdgeInsets.only(left: 10),
                  
                  child: Column(
                    
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Marquee(
                        text: ytResult[index].title,                        
                        style: TextStyle(fontSize:18.0,fontWeight: FontWeight.bold),),
                        
                    ],
                  ),
                )
              ]
            ),
          )
        ],
      ),
    );
  }

2 个答案:

答案 0 :(得分:0)

如下所示将“字幕框”小部件包装在容器中并设置宽度和高度。它解决了我的问题。

Expanded(child : Container(child : Marquee(  height:30,width:MediaQuery.of(context).size.width,text : "Hello Rajesh")))

答案 1 :(得分:0)

测试我意识到在我的案例中真正解决了问题的是将它包装在一个 Expanded() 小部件中,而 Container() 不是必需的...

Expanded(
      child: Marquee(
        text: 'GeeksforGeeks.org was created'
            ' of technology lovers and computer science enthusiasts'
            ' have been constantly working in this direction ',
      ),
    );