“需要'key',但没有相应的参数”flutter错误

ddrv8njm  于 2022-12-19  发布在  Flutter
关注(0)|答案(1)|浏览(139)

如何解决这个错误?

    • 命名参数"key"是必需的,但没有对应的参数。(文档)请尝试添加所需的参数。**
    • 错误**

Future<void> onJoin() async {
    // update input validation
    setState(() {
      _channelController.text.isEmpty
          ? _validateError = true
          : _validateError = false;
    });
    if (_channelController.text.isNotEmpty) {
      await _handleCameraAndMic(Permission.camera);
      await _handleCameraAndMic(Permission.microphone);
      await Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => VideoCall(
            channelName: _channelController.text,
            role: _role,
          ),
        ),
      );
    }
  }
    • 类视频通话**
class VideoCall extends StatefulWidget {
  final String channelName;
  final ClientRole role;
  const VideoCall({Key key, required this.channelName, required this.role})
      : super(key: key);

  @override
  _VideoCallState createState() => _VideoCallState();
}

class _VideoCallState extends State<VideoCall> {
  final _users = <int>[];
  final _infoStrings = <String>[];
  bool muted = false;
  late RtcEngine _engine;

  @override
  void dispose() {
    // clear users
    _users.clear();
    // destroy sdk
    _engine.leaveChannel();
    _engine.destroy();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    // initialize agora sdk
    initialize();
  }

这是videoCall类,没有显示任何错误。
添加"key"时显示此

从视频呼叫类中的键删除所需属性时

显示此错误

b1uwtaje

b1uwtaje1#

VideoCall类中,key属性设置为required,将其更改为optional

class VideoCall extends StatefulWidget {
  final String? channelName;
  final ClientRole? role;
  const VideoCall({Key? key, this.channelName, this.role})
      : super(key: key);

  @override
  _VideoCallState createState() => _VideoCallState();
}

相关问题