londonappbrewery / Clima-Flutter

Starter code for the Clima Project from the Complete Flutter Development Bootcamp
https://www.appbrewery.co
155 stars 740 forks source link

This expression has a type of 'void' so its value can't be used. Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void. #19

Open fanydhilah opened 3 years ago

fanydhilah commented 3 years ago

hello, i am new in this flutter, and i wanna make chatbot app with stt and tts inside it. but i got error in this and i don;t khow what todo, please help me

`class _MyApppState extends State { stt.SpeechToText _speech; bool _isListening = false; String _text = ""; String speak; String qry;

@override void initState() { super.initState(); _speech = stt.SpeechToText(); }

final FlutterTts flutterTts = FlutterTts();

void response(query) async { AuthGoogle authGoogle = await AuthGoogle(fileJson: "assets/newagent-kalbgl-c0fb323bfb4c.json") .build(); Dialogflow dialogflow = Dialogflow(authGoogle: authGoogle, language: Language.indonesian); AIResponse aiResponse = await dialogflow.detectIntent(query); setState(() { messsages.insert(0, { "data": 0, "message": aiResponse.getListMessage()[0]["text"]["text"][0].toString() }); });

print(aiResponse.getListMessage()[0]["text"]["text"][0].toString());

}

void _speak(query) async { print(await flutterTts.getLanguages); await flutterTts.setLanguage('jv-ID'); await flutterTts.speak(query); }

final messageInsert = TextEditingController(); List messsages = List();

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "Jawa Bot", ), backgroundColor: Colors.blueGrey, ), body: Container( child: Column(children: [ Center( child: Container( padding: EdgeInsets.only(top: 15, bottom: 10), child: Text( "Dinten Niki, ${DateFormat("Hm").format(DateTime.now())}", style: TextStyle(fontSize: 15), ), ), ), Flexible( child: ListView.builder( reverse: true, padding: EdgeInsets.all(10.0), itemCount: messsages.length, itemBuilder: (context, index) => chat( messsages[index]["message"].toString(), messsages[index]["data"]))), SizedBox( height: 20, ), Divider( height: 5.0, color: Colors.greenAccent, ), Container( child: ListTile( leading: IconButton( icon: Icon( _isListening ? Icons.mic : Icons.mic_none, color: Colors.greenAccent, size: 35, ), onPressed: () { _listen(); if (_text.isEmpty) { print("empty message"); } else { setState(() { messsages.insert(0, {"data": 1, "message": _text}); }); speak = response(_text); _speak(speak); _text = ''; } FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } }, ), title: Container( decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(15)), color: Color.fromRGBO(220, 220, 220, 1)), padding: EdgeInsets.only(left: 15), child: Row( children: [ Flexible( child: TextField( controller: messageInsert, decoration: InputDecoration( hintText: "Send Your Message", hintStyle: TextStyle(color: Colors.black26), border: InputBorder.none, focusedBorder: InputBorder.none, enabledBorder: InputBorder.none, errorBorder: InputBorder.none, disabledBorder: InputBorder.none, ), style: TextStyle(fontSize: 16, color: Colors.black), )), ], ), ), trailing: IconButton( icon: Icon(Icons.send, size: 30, color: Colors.greenAccent), onPressed: () { if (messageInsert.text.isEmpty) { print("empty message"); } else { setState(() { messsages.insert( 0, {"data": 1, "message": messageInsert.text}); }); response(messageInsert.text); _speak(messageInsert.text); messageInsert.clear(); } FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } }), )), SizedBox( height: 15.0, ) ]), )); }`

i wanna use tts for this text

`oid response(query) async { AuthGoogle authGoogle = await AuthGoogle(fileJson: "assets/newagent-kalbgl-c0fb323bfb4c.json") .build(); Dialogflow dialogflow = Dialogflow(authGoogle: authGoogle, language: Language.indonesian); AIResponse aiResponse = await dialogflow.detectIntent(query); setState(() { messsages.insert(0, { "data": 0, "message": aiResponse.getListMessage()[0]["text"]["text"][0].toString() }); });

print(aiResponse.getListMessage()[0]["text"]["text"][0].toString());

}

void _speak(query) async { print(await flutterTts.getLanguages); await flutterTts.setLanguage('jv-ID'); await flutterTts.speak(query); } `

and i put it like this

onPressed: () { _listen(); if (_text.isEmpty) { print("empty message"); } else { setState(() { messsages.insert(0, {"data": 1, "message": _text}); }); speak = response(_text); _speak(speak); _text = ''; } FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } },

i don't know how to fix this, please help me, thankyou