Flutter Speech to text navigate next Sacreen after finishing up the speech

Viewed 71

Hello friends my problem is that I want perform task there small icon on menu bar mic icon when user click on Mic it show dialog box and when they speak text word appear on dialog box when user finished up there speech it's goes to next screen I have done all thing but problem is that when user finishing there speech i unable to go on next sacreen this only issue any expert can help here is picture below what i actually i want

Here is when user speech

When they complete their speech go next sacreen

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:speech_to_text/speech_recognition_result.dart';
import 'package:speech_to_text/speech_to_text.dart' as stt;
import 'package:speech_to_text/speech_to_text.dart';
import 'package:avatar_glow/avatar_glow.dart';


class Booknames extends StatefulWidget {
  const Booknames({Key? key}) : super(key: key);

  @override
  _BooknamesState createState() => _BooknamesState();
}

class _BooknamesState extends State<Booknames> {




  stt.SpeechToText speechToText = stt.SpeechToText();
  bool islistening = false;
  late String text = 'Example:Gensis chapter verse 5';
  bool complete=false;



  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _initSpeech();
  }

  /// This has to happen only once per app
  void _initSpeech() async {
    speechToText.initialize();
  }
  final GlobalKey _dialogKey = GlobalKey();

  _showDialog() async {
    showDialog(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return StatefulBuilder(
          key: _dialogKey,
          builder: (context, setState) {
            return Container(
              child: Dialog(
                child: Padding(
                  padding: EdgeInsets.all(8),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      AvatarGlow(
                        glowColor: Colors.blue,
                        endRadius: 80,
                        duration: Duration( milliseconds:  2500),
                        repeat: true,
                        showTwoGlows: true,
                        repeatPauseDuration: Duration( milliseconds:  150),
                        child: Material(
                          elevation: 5,
                          shape: CircleBorder(),
                          child: CircleAvatar(
                            backgroundColor: Colors.white,
                            child: Icon(Icons.mic, color: Colors.blue, size: 40,),
                            radius: 40,
                          ),
                        ),

                      ),
                      Text(text),

                      SizedBox(height: 10),
                      TextButton(
                        onPressed: () => Navigator.pop(context, false), // passing false
                        child: Text('Cancel Voice'),
                      ),


                    ],
                  ),
                ),

              ),
            );
          },
        );
      },
    );

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: <Widget>[
          new IconButton(
            icon: new Icon(islistening ? Icons.mic : Icons.mic_none),
            highlightColor: Colors.pink,
            onPressed: () {
              setState(() {
                _listen();
                _showDialog();

              });
            },
          ),

        ],
        elevation: 0,
        title: Text('The Bible Multiversion', style: TextStyle(
            fontSize: 20
        ),),
        centerTitle: true,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: ListView.separated(
              shrinkWrap: true,
              itemCount: 1,
              separatorBuilder: (BuildContext context, int index) =>
                  Divider(height: 1),
              itemBuilder: (context, index) {
                return Column(
                  children: [


                  ],

                );
              },

            ),
          ),
        ],

      ),
    );
  }
  void _listen() async {
    if (!islistening) {
      bool available = await speechToText.initialize(
        onStatus: (val) => print('onStatus: $val'),
        onError: (val) => print('onError: $val'),
      );
      if (available) {
        setState(() {
          islistening = true;
        });
        speechToText.listen(
            onResult: (result) =>
                setState(() {
                  text = result.recognizedWords;
                  if (_dialogKey.currentState != null && _dialogKey.currentState!.mounted) {
                    _dialogKey.currentState!.setState(() {
                      text =result.recognizedWords;



                    });


                  }


                })


        );

      }
    } else {
      setState(() => islistening = false

      );
      speechToText.stop();
    }
  }


}
0 Answers
Related