如何在Flutter代码的相机图标前添加「Add Photo」文本
实现方法
你只需要把原Container组件的child属性从单独的Icon组件,替换为Row水平布局组件,按顺序放置「Add photo」文本组件和相机图标组件即可,可按需调整文本样式和组件间距。
修改后的完整代码如下:
InkWell( onTap: (){ _pickImage(); }, child: Container( padding: EdgeInsets.all(5), decoration: BoxDecoration( borderRadius: BorderRadius.circular(40.0), color: Colors.transparent, ), margin: EdgeInsets.only(left: 30, top: 70), // 替换原有Icon为Row布局实现图文并列 child: Row( mainAxisSize: MainAxisSize.min, // 仅适配内容宽度,不占用多余横向空间 children: [ Text( "Add photo", style: TextStyle( color: Colors.white, fontSize: 16, ), ), SizedBox(width: 8), // 文本和图标之间的间距,可按需调整数值 Icon( Icons.photo_camera, size: 25, color: Colors.white, ), ], ), ), ),
内容的提问来源于stack exchange,提问作者Usama Bin Tahir
相关产品推荐
相关产品推荐

