Flutter- [错误:flutter / lib / ui / ui_dart_state.cc(166)]未处理的异常:'未选择过滤器。预期其中之一:id,channelId,我的

时间:2020-06-20 02:39:38

标签: json flutter mobile

使用Youtube数据API时出现类似错误;

E/flutter ( 4218): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: 'No filter selected. Expected one of: id, channelId, mine'
E/flutter ( 4218): #0      APIService.fetchVideosFromPlaylist (package:niro_speaks/services/api_services.dart:81:7)
E/flutter ( 4218): <asynchronous suspension>
E/flutter ( 4218): #1      APIService.fetchChannel (package:niro_speaks/services/api_services.dart:38:30)
E/flutter ( 4218): <asynchronous suspension>

这就是我获取api并在api_services.dart中实现的方式

 Future<Channel> fetchChannel({String channelId}) async {
    Map<String, String> parameters = {
      'part': 'snippet, contentDetails, statistics',
      'id': channelId,
      'key': API_KEY,
    };
    Uri uri = Uri.https(
      _baseUrl,
      '/youtube/v3/channels',
      parameters,
    );
    Map<String, String> headers = {
      HttpHeaders.contentTypeHeader: 'application/json',
    };

    // Get Channel
    var response = await http.get(uri, headers: headers);
    if (response.statusCode == 200) {
      Map<String, dynamic> data = json.decode(response.body)['items'][0];
      Channel channel = Channel.fromMap(data);

      // Fetch first batch of videos from uploads playlist
      channel.videos = await fetchVideosFromPlaylist(
        playlistId: channel.uploadPlaylistId,
      );
      return channel;
    } else {
      throw json.decode(response.body)['error']['message'];
    }
  }

有人请帮助我解决此错误吗?

0 个答案:

没有答案