-1

I am making a text translation application using Flutter which is supposed to read the text from an input text file and then translate it into a selected language and displaly it.

My code works but I am having to close and restart the application everytime I change the text in the input file for the application to load in the new text. How to make the application read and load the new text if I change the text in the file?

I used the below:

`getData() async {
    String response;
    response = await rootBundle.loadString('assets/trans_input.txt');
    setState(() {
         userinput = response;
    });

}

//Translate
resultTranslate() async {
    String response;
    response = await rootBundle.loadString('assets/trans_input.txt');
    setState(() {
        userinput = response;
        print(response);
   });
    setState(() {
        result = translation.text;
        tts.speak(result);
    });`

1 Answers1

0

You can do in any of the following way:

  1. You can make a reset button, that way whenever user clicks on it you can reset the local variable of your response.

  2. If you are using File picker or something like that then you can directly reset the response if the response is not null/empty. Here's how you can achieve it:

resetData() async {
    String response;
    response.isNotEmpty ? response=null:null; //if response=null dosen't work then try response=""
    setState(() {});
}
Cavin Macwan
  • 1,183
  • 5
  • 12