@@ -28,22 +28,22 @@ class MicStreamExampleApp extends StatefulWidget {
2828
2929class _MicStreamExampleAppState extends State <MicStreamExampleApp >
3030 with SingleTickerProviderStateMixin , WidgetsBindingObserver {
31- Stream stream;
32- StreamSubscription listener;
33- List <int > currentSamples = [];
31+ Stream ? stream;
32+ late StreamSubscription listener;
33+ List <int >? currentSamples = [];
3434 List <int > visibleSamples = [];
35- int localMax;
36- int localMin;
35+ int ? localMax;
36+ int ? localMin;
3737
3838
3939 // Refreshes the Widget for every possible tick to force a rebuild of the sound wave
40- AnimationController controller;
40+ late AnimationController controller;
4141
4242 Color _iconColor = Colors .white;
4343 bool isRecording = false ;
4444 bool memRecordingState = false ;
45- bool isActive;
46- DateTime startTime;
45+ late bool isActive;
46+ DateTime ? startTime;
4747
4848 int page = 0 ;
4949 List state = ["SoundWavePage" , "IntensityWavePage" , "InformationPage" ];
@@ -53,7 +53,7 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
5353 void initState () {
5454 print ("Init application" );
5555 super .initState ();
56- WidgetsBinding .instance.addObserver (this );
56+ WidgetsBinding .instance! .addObserver (this );
5757 setState (() {
5858 initPlatformState ();
5959 });
@@ -80,8 +80,8 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
8080 ! isRecording ? await _startListening () : _stopListening ();
8181
8282
83- int bytesPerSample;
84- int samplesPerSecond;
83+ late int bytesPerSample;
84+ late int samplesPerSecond;
8585
8686 Future <bool > _startListening () async {
8787 print ("STARRT LISTENING" );
@@ -98,8 +98,8 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
9898 // after invoking the method for the first time, though, these will be available;
9999 // It is not necessary to setup a listener first, the stream only needs to be returned first
100100 print ("Start Listening to the microphone, sample rate is ${await MicStream .sampleRate }, bit depth is ${await MicStream .bitDepth }, bufferSize: ${await MicStream .bufferSize }" );
101- bytesPerSample = (await MicStream .bitDepth / 8 ).toInt ();
102- samplesPerSecond = (await MicStream .sampleRate).toInt ();
101+ bytesPerSample = (( await MicStream .bitDepth) ! / 8 ).toInt ();
102+ samplesPerSecond = (await MicStream .sampleRate)! .toInt ();
103103 localMax = null ;
104104 localMin = null ;
105105
@@ -108,7 +108,7 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
108108 startTime = DateTime .now ();
109109 });
110110 visibleSamples = [];
111- listener = stream.listen (_calculateSamples);
111+ listener = stream! .listen (_calculateSamples);
112112 return true ;
113113 }
114114
@@ -121,7 +121,7 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
121121
122122 void _calculateWaveSamples (samples) {
123123 bool first = true ;
124- visibleSamples = List () ;
124+ visibleSamples = [] ;
125125 int tmp = 0 ;
126126 for (int sample in samples) {
127127 if (sample > 128 ) sample -= 255 ;
@@ -133,8 +133,8 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
133133
134134 localMax ?? = visibleSamples.last;
135135 localMin ?? = visibleSamples.last;
136- localMax = max (localMax, visibleSamples.last);
137- localMin = min (localMin, visibleSamples.last);
136+ localMax = max (localMax! , visibleSamples.last);
137+ localMin = min (localMin! , visibleSamples.last);
138138
139139 tmp = 0 ;
140140 }
@@ -146,20 +146,20 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
146146 void _calculateIntensitySamples (samples) {
147147 currentSamples ?? = [];
148148 int currentSample = 0 ;
149- eachWithIndex (samples, (i, sample) {
149+ eachWithIndex (samples, (i, int sample) {
150150 currentSample += sample;
151151 if ((i % bytesPerSample) == bytesPerSample- 1 ) {
152- currentSamples.add (currentSample);
152+ currentSamples! .add (currentSample);
153153 currentSample = 0 ;
154154 }
155155 });
156156
157- if (currentSamples.length >= samplesPerSecond/ 10 ) {
158- visibleSamples.add (currentSamples.map ((i) => i).toList ().reduce ((a, b) => a+ b));
157+ if (currentSamples! .length >= samplesPerSecond/ 10 ) {
158+ visibleSamples.add (currentSamples! .map ((i) => i).toList ().reduce ((a, b) => a+ b));
159159 localMax ?? = visibleSamples.last;
160160 localMin ?? = visibleSamples.last;
161- localMax = max (localMax, visibleSamples.last);
162- localMin = min (localMin, visibleSamples.last);
161+ localMax = max (localMax! , visibleSamples.last);
162+ localMin = min (localMin! , visibleSamples.last);
163163 currentSamples = [];
164164 setState (() {});
165165 }
@@ -275,19 +275,19 @@ class _MicStreamExampleAppState extends State<MicStreamExampleApp>
275275 void dispose () {
276276 listener.cancel ();
277277 controller.dispose ();
278- WidgetsBinding .instance.removeObserver (this );
278+ WidgetsBinding .instance! .removeObserver (this );
279279 super .dispose ();
280280 }
281281}
282282
283283class WavePainter extends CustomPainter {
284- int localMax;
285- int localMin;
286- List <int > samples;
287- List <Offset > points;
288- Color color;
289- BuildContext context;
290- Size size;
284+ int ? localMax;
285+ int ? localMin;
286+ List <int >? samples;
287+ late List <Offset > points;
288+ Color ? color;
289+ BuildContext ? context;
290+ Size ? size;
291291
292292 // Set max val possible in stream, depending on the config
293293 // int absMax = 255*4; //(AUDIO_FORMAT == AudioFormat.ENCODING_PCM_8BIT) ? 127 : 32767;
@@ -296,16 +296,16 @@ class WavePainter extends CustomPainter {
296296 WavePainter ({this .samples, this .color, this .context, this .localMax, this .localMin});
297297
298298 @override
299- void paint (Canvas canvas, Size size) {
300- this .size = context.size;
299+ void paint (Canvas canvas, Size ? size) {
300+ this .size = context! .size;
301301 size = this .size;
302302
303303 Paint paint = new Paint ()
304- ..color = color
304+ ..color = color!
305305 ..strokeWidth = 1.0
306306 ..style = PaintingStyle .stroke;
307307
308- if (samples.length == 0 )
308+ if (samples! .length == 0 )
309309 return ;
310310
311311
@@ -321,13 +321,13 @@ class WavePainter extends CustomPainter {
321321 bool shouldRepaint (CustomPainter oldPainting) => true ;
322322
323323 // Maps a list of ints and their indices to a list of points on a cartesian grid
324- List <Offset > toPoints (List <int > samples) {
324+ List <Offset > toPoints (List <int >? samples) {
325325 List <Offset > points = [];
326326 if (samples == null )
327- samples = List <int >.filled (size.width.toInt (), (0.5 ).toInt ());
328- double pixelsPerSample = size.width/ samples.length;
327+ samples = List <int >.filled (size! .width.toInt (), (0.5 ).toInt ());
328+ double pixelsPerSample = size! .width/ samples.length;
329329 for (int i = 0 ; i < samples.length; i++ ) {
330- var point = Offset (i * pixelsPerSample, 0.5 * size.height * pow ((samples[i] - localMin)/ (localMax - localMin), 5 ));
330+ var point = Offset (i * pixelsPerSample, 0.5 * size! .height * pow ((samples[i] - localMin! )/ (localMax! - localMin! ), 5 ));
331331 points.add (point);
332332 }
333333 return points;
@@ -341,7 +341,7 @@ class WavePainter extends CustomPainter {
341341
342342class Statistics extends StatelessWidget {
343343 final bool isRecording;
344- final DateTime startTime;
344+ final DateTime ? startTime;
345345
346346 final String url = "https://github.com/anarchuser/mic_stream" ;
347347
@@ -360,7 +360,7 @@ class Statistics extends StatelessWidget {
360360 ListTile (
361361 leading: Icon (Icons .access_time),
362362 title: Text ((isRecording
363- ? DateTime .now ().difference (startTime).toString ()
363+ ? DateTime .now ().difference (startTime! ).toString ()
364364 : "Not recording" ))),
365365 ]);
366366 }
0 commit comments