forked from pranky89/enhanced_flutter_speech_to_text
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phone_screen.dart
103 lines (93 loc) · 2.8 KB
/
phone_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import 'package:google_fonts/google_fonts.dart'; // Add this for custom fonts
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'provider.dart'; // your provider file, make sure to change it.....
import 'package:shared_preferences/shared_preferences.dart';
class PhoneCallScreen extends StatefulWidget {
const PhoneCallScreen({
Key? key,
}) : super(key: key);
@override
_PhoneCallScreenState createState() => _PhoneCallScreenState();
}
class _PhoneCallScreenState extends State<PhoneCallScreen> {
SpeechProvider? _speechProvider;
bool _isInitialized = false;
Duration _callDuration = Duration.zero;
Timer? _timer;
@override
void initState() {
super.initState();
}
void _startCallTimer() {
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
setState(() {
_callDuration += Duration(seconds: 1);
});
});
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_speechProvider = Provider.of<SpeechProvider>(context, listen: false);
if (!_isInitialized) {
_initializeSpeechProvider();
_isInitialized = true;
}
}
Future<void> _initializeSpeechProvider() async {
if (_speechProvider != null) {
_startCallTimer();
await _speechProvider!.initializeForMe(); //this will start everything
}
}
@override
void dispose() {
printDebugStatement('Calling dispose for phone page..');
super.dispose();
printDebugStatement('Dispose ran for phone page');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: 50,
),
const SizedBox(height: 10),
Text(
widget.botName,
style: GoogleFonts.lato(
textStyle: TextStyle(color: Colors.black, fontSize: 20),
),
),
const SizedBox(height: 20),
Text(
'${_callDuration.inMinutes}:${(_callDuration.inSeconds % 60).toString().padLeft(2, '0')}',
style: GoogleFonts.lato(
textStyle: TextStyle(color: Colors.black, fontSize: 24),
),
),
const SizedBox(height: 20),
Consumer<SpeechProvider>(
builder: (context, speechProvider, child) {
return Text(
'Listening...',
style: GoogleFonts.lato(
textStyle: TextStyle(color: Colors.blue, fontSize: 24),
),
);
},
),
],
),
),
);
}
}