通过文件选择器Flutter显示文件名



我需要在按钮下显示添加的文件名。我正在使用file_picker添加图像。添加图像后,我需要删除或替换该图像。之后,我需要将该图片发送到电子邮件。我正在使用EmailJS提交表格。

Padding(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
child: RaisedButton(
elevation: 0,
onPressed: () async{
final result = await FilePicker.platform.pickFiles();
if(result == null) return;
final file = result.files.first;
//openFile(file);
},
color: Colors.white,
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.green,
width: 1),
borderRadius: BorderRadius.all(Radius.circular(0),
),
),
child: Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Qatar ID',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.normal,
color: Colors.green,
),
),
Icon(
Icons.upload_sharp,
color: Colors.green,
)
],
),
),
),
),

请参阅以下代码:

File file = new File("/storage/emulated/0/Android/data/gallery/images/pictureone.png"); 
String fileName = file.path.split('/').last;
print("File Name: $fileName");

最新更新