Home > OS >  The parameter onResult null
The parameter onResult null

Time:01-18

I have a problem when making text to speech following the tutorial on youtube.

The parameter 'onResult' can't have a value of 'null' because of its type, but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier.

I hope you can help me

import 'package:flutter/cupertino.dart';
import 'package:speech_to_text/speech_to_text.dart';

class speechAPI {
  static final _speech = SpeechToText();

  static Future<bool> toggleRecording({
    @required Function(String text) onResult,
    @required ValueChanged<bool> onListening,
  }) async {
    if (_speech.isListening) {
      _speech.stop();
      return true;
    }

final isAvailable = await _speech.initialize(
  onStatus: (status) => onListening(_speech.isListening),
  one rror: (e) => print('Eror: $e'),
);
  

if (isAvailable) {
  _speech.listen(onResult:(value) => onResult(value.recognizedWords),);
}

    return isAvailable;
  }
}

CodePudding user response:

Since Dart 2.12 you should not use @required. Instead use required.

From:

    @required Function(String text) onResult,
    @required ValueChanged<bool> onListening,

To:

    required Function(String text) onResult,
    required ValueChanged<bool> onListening,

This might be the issue, depending on what version you are on.

CodePudding user response:

Try renaming the callback parameter @required Function(String text) onResult, to something else and see if it works.

  •  Tags:  
  • Related