커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
_TypeError (type 'String' is not a subtype of type 'List<dynamic>') 오류발생
[왕초보] 플러터(Flutter)로 시작하는 앱개발 종합반 v0
4주차
북마크
남*태
댓글
3
추천
0
조회수
15
조회수
15
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


Exception has occurred.


_TypeError (type 'String' is not a subtype of type 'List<dynamic>')

오류가 생깁니다.



스파르타 즉문즉답




작성한 코드 및 에러 메세지

import 'package:dio/dio.dart';

import 'package:flutter/material.dart';


import 'book.dart';


class BookService extends ChangeNotifier {

  List<Book> bookList = []; // 책 목록

  List<Book> likedBookList = [];


  void toggleLikeBook({required Book book}) {

    String bookId = book.id;

    if (likedBookList.map((book) => book.id).contains(bookId)) {

      likedBookList.removeWhere((book) => book.id == bookId);

    } else {

      likedBookList.add(book);

    }

    notifyListeners();

  }


  void search(String q) async {

    bookList.clear(); // 검색 버튼 누를때 이전 데이터들을 지워주기


    if (q.isNotEmpty) {

      Response res = await Dio().get(

        "https://www.googleapis.com/books/v1/volumes?q=$q&startIndex=0&maxResults=40",

      );

      List items = res.data["items"];


      for (Map<String, dynamic> item in items) {

        Book book = Book(

          id: item['id'],

          title: item['volumeInfo']['title'] ?? "",

          subtitle: item['volumeInfo']['subtitle'] ?? "",

          authors: item['volumeInfo']['authors'] ?? "",

          publishedDate: item['volumeInfo']['publishedDate'] ?? "",

          thumbnail: item['volumeInfo']['imageLinks']?['thumbnail'] ??

              "https://thumbs.dreamstime.com/b/no-image-available-icon-flat-vector-no-image-available-icon-flat-vector-illustration-132482953.jpg",

          previewLink: item['volumeInfo']['previewLink'] ?? "",

        );

        bookList.add(book);

      }

    }

    notifyListeners();

  }

}





취소
 공유
취소
댓글 0
댓글 알림
나의얼굴