import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/provider/robot_provider.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'dart:async'; class SpeechToText { final BuildContext context; static var dialog; SpeechToText({ @required this.context, }); showAlertDialog(BuildContext context) { //AlertDialog alert = AlertDialog // AlertDialog alert = AlertDialog(content: MyStatefulBuilder(dispose: () { // print('dispose!!!!!!!!!!!!'); // }) // isClosed = true; // streamSubscription.cancel(); // }, builder: (BuildContext context, StateSetter setState) { // //print(streamSubscription); // }), // ); // show the dialog showDialog( context: context, barrierDismissible: true, builder: (BuildContext context) { dialog = context; return MyStatefulBuilder( dispose: () {}, ); }, ); print(dialog); } static closeAlertDialog(BuildContext context) { Navigator.of(dialog).pop(); } } typedef Disposer = void Function(); class MyStatefulBuilder extends StatefulWidget { const MyStatefulBuilder({ // @required this.builder, @required this.dispose, }); //final StatefulWidgetBuilder builder; final Disposer dispose; @override _MyStatefulBuilderState createState() => _MyStatefulBuilderState(); } class _MyStatefulBuilderState extends State { var event = RobotProvider(); var searchText; static StreamSubscription streamSubscription; static var isClosed = false; @override void initState() { streamSubscription = event.controller.stream.listen((p) { if ((p['searchText'] != 'null' && p['searchText'] != null && p['searchText'] != "" && isClosed == false) && mounted) { setState(() { searchText = p['searchText']; }); } else if (p['searchText'] == 'null') { setState(() { searchText = p['searchText']; }); } }); super.initState(); } @override Widget build(BuildContext context) => AlertDialog( content: Container( color: Colors.white, height: SizeConfig.realScreenHeight * 0.5, width: SizeConfig.realScreenWidth * 0.8, child: Container( child: Column(children: [ Expanded( flex: 1, child: Center( child: Image.asset( 'assets/images/habib-logo.png', height: 75, width: 75, ))), Expanded( flex: 3, child: Center( child: Container( margin: EdgeInsets.all(20), padding: EdgeInsets.all(10), decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), border: Border.all(width: 2, color: Colors.red)), child: Icon( Icons.mic, color: Colors.blue, size: 48, ), ))), Expanded( flex: 1, child: Center( child: Image.asset( 'assets/images/soundWaveAnimation.gif', height: 75, ))), Expanded( flex: 1, child: Center( child: AppText(searchText != null && searchText != 'null' ? searchText : TranslationBase.of(context).trySaying))), searchText == 'null' ? Center( child: RaisedButton( child: AppText('Retry'), onPressed: () { SpeechToText.closeAlertDialog(context); event.setValue({'startPopUp': 'true'}); }, )) : SizedBox() ]), ))); @override void dispose() { super.dispose(); widget.dispose(); } }