voice command
parent
da317431ba
commit
3ad928902b
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
@ -1,80 +1,249 @@
|
||||
import 'package:diplomaticquarterapp/config/size_config.dart';
|
||||
import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart';
|
||||
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
||||
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
|
||||
import 'package:diplomaticquarterapp/widgets/others/floating_button_search.dart';
|
||||
import 'package:diplomaticquarterapp/widgets/robo-search/search.dart';
|
||||
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class RoboSearch {
|
||||
final BuildContext context;
|
||||
var event = RobotProvider();
|
||||
var searchText = null;
|
||||
RoboSearch({
|
||||
@required this.context,
|
||||
});
|
||||
class RoboSearch extends StatefulWidget {
|
||||
@override
|
||||
_RoboSearch createState() => new _RoboSearch();
|
||||
}
|
||||
|
||||
showAlertDialog(BuildContext context) {
|
||||
// set up the buttons
|
||||
class _RoboSearch extends State<RoboSearch> {
|
||||
var event = RobotProvider();
|
||||
var searchText = '';
|
||||
bool isRetry = false;
|
||||
var tween = Tween(begin: 0.0, end: 1.0).chain(CurveTween(curve: Curves.ease));
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
content: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
setState((){
|
||||
event.controller.stream.listen((p) {
|
||||
if (p['searchText']!=null) {
|
||||
setState(() {
|
||||
searchText = p['searchText'];
|
||||
});
|
||||
}
|
||||
});
|
||||
@override
|
||||
void initState() {
|
||||
event.controller.stream.listen((p) {
|
||||
if (p['searchText'] != null) {
|
||||
if (p['searchText'] == 'null') {
|
||||
//Future.delayed(const Duration(seconds: 1), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isRetry = true;
|
||||
searchText = '';
|
||||
});
|
||||
return Container(
|
||||
}
|
||||
//});
|
||||
} else {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
searchText = p['searchText'];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return 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: Text( searchText != null ? searchText : 'Try saying something' )))
|
||||
]),
|
||||
));
|
||||
}),
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static closeAlertDialog(BuildContext context) {
|
||||
Navigator.of(context).pop();
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
isRetry == true
|
||||
? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.all(20),
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.circular(100),
|
||||
border: Border.all(
|
||||
width: 5, color: Colors.red)),
|
||||
child: Icon(
|
||||
Icons.mic,
|
||||
color: Colors.blue,
|
||||
size: 48,
|
||||
)),
|
||||
Center(
|
||||
child: AppText(
|
||||
"Didn't catch that, Try speaking again",
|
||||
fontSize: 14,
|
||||
)),
|
||||
RaisedButton(
|
||||
color: Colors.transparent,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
isRetry = false;
|
||||
});
|
||||
FloatingSearchButton()
|
||||
.createState()
|
||||
.startVoiceSearch();
|
||||
},
|
||||
child: AppText(
|
||||
'Try again',
|
||||
color: Colors.blue,
|
||||
))
|
||||
])
|
||||
: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.all(20),
|
||||
padding: EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(100)),
|
||||
child: Icon(
|
||||
Icons.mic,
|
||||
color: Colors.white,
|
||||
size: 48,
|
||||
)),
|
||||
SizedBox(height: 20),
|
||||
Center(
|
||||
child: Text(searchText == ''
|
||||
? 'Try saying something'
|
||||
: searchText))
|
||||
],
|
||||
)
|
||||
]),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
// class RoboSearch {
|
||||
// final BuildContext context;
|
||||
// var event = RobotProvider();
|
||||
// var searchText = '';
|
||||
// bool isRetry = false;
|
||||
// var tween = Tween(begin: 0.0, end: 1.0).chain(CurveTween(curve: Curves.ease));
|
||||
// RoboSearch({
|
||||
// @required this.context,
|
||||
// });
|
||||
|
||||
// showAlertDialog(BuildContext context) {
|
||||
// // set up the buttons
|
||||
|
||||
// // set up the AlertDialog
|
||||
// AlertDialog alert = AlertDialog(
|
||||
// content: StatefulBuilder(
|
||||
// builder: (BuildContext context, StateSetter setState) {
|
||||
|
||||
// event.controller.stream.listen((p) {
|
||||
// if (p['searchText'] != null) {
|
||||
// if (p['searchText'] == 'null') {
|
||||
// Future.delayed(const Duration(seconds: 1), ()
|
||||
// {
|
||||
// setState(() {
|
||||
// isRetry = true;
|
||||
// searchText = '';
|
||||
// });
|
||||
// });
|
||||
// } else {
|
||||
// Future.delayed(const Duration(seconds: 1), ()
|
||||
// {
|
||||
// setState(() {
|
||||
// searchText = p['searchText'];
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// return Container(
|
||||
// color: Colors.white,
|
||||
// height: SizeConfig.realScreenHeight * 0.5,
|
||||
// width: SizeConfig.realScreenWidth * 0.8,
|
||||
// child: Container(
|
||||
// child: Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// isRetry == true
|
||||
// ? Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// Container(
|
||||
// margin: EdgeInsets.all(20),
|
||||
// padding: EdgeInsets.all(10),
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius:
|
||||
// BorderRadius.circular(100),
|
||||
// border: Border.all(
|
||||
// width: 5, color: Colors.red)),
|
||||
// child: Icon(
|
||||
// Icons.mic,
|
||||
// color: Colors.blue,
|
||||
// size: 48,
|
||||
// )),
|
||||
// Center(
|
||||
// child: AppText(
|
||||
// "Didn't catch that, Try speaking again",
|
||||
// fontSize: 14,
|
||||
// )),
|
||||
// RaisedButton(
|
||||
// color: Colors.transparent,
|
||||
// onPressed: () {
|
||||
// setState(() {
|
||||
// isRetry = false;
|
||||
|
||||
// });
|
||||
// startVoiceSearch();
|
||||
// },
|
||||
// child: AppText(
|
||||
// 'Try again',
|
||||
// color: Colors.blue,
|
||||
// ))
|
||||
// ])
|
||||
// : Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// Container(
|
||||
// margin: EdgeInsets.all(20),
|
||||
// padding: EdgeInsets.all(20),
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.blue,
|
||||
// borderRadius: BorderRadius.circular(100)),
|
||||
// child: Icon(
|
||||
// Icons.mic,
|
||||
// color: Colors.white,
|
||||
// size: 48,
|
||||
// )),
|
||||
// SizedBox(height: 20),
|
||||
// Center(
|
||||
// child: Text(searchText == ''
|
||||
// ? 'Try saying something'
|
||||
// : searchText))
|
||||
// ],
|
||||
// )
|
||||
// ]),
|
||||
// ));
|
||||
// }),
|
||||
// );
|
||||
|
||||
// // show the dialog
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// builder: (BuildContext context) {
|
||||
// return alert;
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
|
||||
// static closeAlertDialog(BuildContext context) {
|
||||
// Navigator.of(context).pop();
|
||||
// }
|
||||
|
||||
// startVoiceSearch() {
|
||||
|
||||
// // Navigator.of(context).pop();
|
||||
// //this.showAlertDialog(context);
|
||||
// // new RoboSearch(context: context).showAlertDialog(context);
|
||||
// FloatingSearchButton().createState().startVoiceSearch();
|
||||
// }
|
||||
// }
|
||||
|
||||
Loading…
Reference in New Issue