1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] filepicker windows getfilepath returns null on startup

Discussão em 'Mobile' iniciado por Stack, Outubro 3, 2024 às 15:42.

  1. Stack

    Stack Membro Participativo

    I am using Flutter package: filepicker_windows.

    I need to open a file and extract the full filepath then display the full filepath in the text widget.

    The problem is that, on app startup, the filepath shows null.

    After I select a file, I see the fullpath like this:

    File: 'C:\test\myfile.text'

    I want to see: C:\test\myfile.text

    if I try to trim or get a substring, then I get the message that I am out of range b/c the max length is 4. The 4 length refers to null.

    Please advise what should I do.

    Thank you

    Here is my code:

    File? result1;

    File? selectFile() {
    final file = OpenFilePicker()
    ..filterSpecification = {
    'Text Document (*.txt)': '*.txt'
    }
    ..defaultFilterIndex = 0
    ..defaultExtension = 'txt'
    ..title = 'Select a document';
    setState(() {
    result1 = file.getFile();
    });
    return result1;
    }

    String getFilePath(){
    String abc1='';
    setState(() {
    abc1 = result1.toString();
    });
    return abc1;
    }

    Widget mytext = Text(getFilePath().length.toString());

    Continue reading...

Compartilhe esta Página