Home > Back-end >  Display file name through file picker Flutter
Display file name through file picker Flutter

Time:03-29

I need to display the added filename under the button. I'm using file_picker to add the image. after adding the image I need to remove or replace the image. after that, I need to send that image to email. I'm using EmailJS to submit a form.

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,
                  )
                ],
              ),
            ),
          ),
        ),

CodePudding user response:

to get the file name you can simply use file.name

CodePudding user response:

Please refer to the below code:

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