Flutter 自定义一个右侧可滑动 左侧为按钮的组件
  C40WhY6GHXN0 2024年01月13日 31 0

Flutter 自定义一个右侧可滑动 左侧为按钮的组件

   var topicList = ["圈子话题1","圈子话题2","圈子话题3","圈子话题4-天气很好","圈子话题5","圈子话题6"];
   @override
   Widget build(BuildContext context){
     return SizedBox(
        height:40 ,
        child:
        Stack(
          children:[
            Container(
              height: 40,
              margin:  EdgeInsets.fromLTRB( 10, 0,  40, 0),
              child: SingleChildScrollView(
                scrollDirection: Axis.horizontal,
                child: Row(
                  children: [
                    for (int i = 0 ;i < topicList.length;i++)
                      //TopicItem为自定义组件
                      TopicItem(topicString: topicList[i]) ,
                  ],
                ),//Row
              ),//SingleChildScrollView
            ),//Container
            Container(
              width: 40, 
              height:40,
              margin: EdgeInsets.only(left:336),
              child: ElevatedButton(
                  onPressed: ()=>{
                     
                  },
                  style:const ButtonStyle(backgroundColor: MaterialStatePropertyAll(Colors.black)),
                  child:const Image(image: AssetImage("image/detail_cell.png"),),
               
              ),//ElevatedButton
            )//Container
          ],//children
        )//Stack
     );//SizedBox
   }

TopicItem自定义组件:

class TopicItem extends StatelessWidget{
 final String topicString;
 const TopicItem({Key? key,required this.topicString}):super(key:key);
  @override
  Widget build(BuildContext context){
     return  Card(
         child:SizedBox(
            child: Text(topicString,style:const TextStyle(fontSize: 16),),
         ),
     );
  }

}

效果如下:

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2024年01月13日 0

暂无评论

推荐阅读
  ziPvxBHxaaMY   2023年11月01日   88   0   0 Flutter
  z2gOtjXqPXoD   2024年03月04日   79   0   0 Flutter
C40WhY6GHXN0