i have school project,we are currently doing voice controlled kiosk and the navigation through app will be with voice commands,im doing the application part but im having hard times with integrating with ml team,so the thing is they take the voice command and write it to txt file,the process goes like write one-wait for another one-delete existing one-write the new one.
i coded this but then i learned future reads just once,it doesnt update the value when file is changed,im new to flutter and my programming skills are not good enough,i really need help,i think i need to use stream and i tried to convert it to stream but couldnt succeded so yeah i want to learn how to read that txt file constantly and then update the value when new one came
class _MainScreenState extends State<MainScreen> {
List<String> _questions = [];
String answer;
Future<List<String>> _loadQuestions() async {
List<String> questions = [];
await rootBundle.loadString('assets/ml.txt').then((q) {
for (String i in LineSplitter().convert(q)) {
questions.add(i);
}
});
return questions;
}
Timer timer;
@override
void initState() {
_setup();
super.initState();
timer = Timer.periodic(Duration(seconds: 5), (Timer t) => navigate());
}
_setup() async {
// Retrieve the questions (Processed in the background)
List<String> questions = await _loadQuestions();
// Notify the UI and display the questions
setState(() {
_questions = questions;
});
}
void navigate() async {
answer = _questions[0];
print(answer);
setState(() {
if (answer == 'one') {
Navigator.push(
context, MaterialPageRoute(builder: (context) => Majors()));
timer.cancel();
} else if (answer == 'two') {
Navigator.push(
context, MaterialPageRoute(builder: (context) => Administrative()));
} else if (answer == 'three') {
Navigator.push(
context, MaterialPageRoute(builder: (context) => Classes()));
}
});
}
Widget build(BuildContext context) {