커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
똑같은 변수 기능인가요?
앱개발 종합반 - 플러터 v8
4주차
북마크
권*호
댓글
8
추천
0
조회수
16
조회수
16
답변 완료

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

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


itemBuilder: (context, index) {

                if (bookService.bookList.isEmpty) return SizedBox();

                Book book = bookService.bookList.elementAt(index);

                return ListTile(

                  onTap: () {},

                  leading: Image.network(

                    book.thumbnail,

                    fit: BoxFit.fitHeight,

                  ),

                  title: Text(

                    book.title,

                    style: TextStyle(fontSize: 16),

                  ),

                  subtitle: Text(

                    book.subtitle,

                    style: TextStyle(color: Colors.grey),

                  ),

                  trailing: IconButton(

                    onPressed: () {},

                    icon: Icon(Icons.star_border),

                  ),

                );

              },






class BookService extends ChangeNotifier {

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


  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'] ?? "",

          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();

  }

}



에서 Book book =bookService.bookList.elementAt(index); 로 되어 있는 변수 book과 book_service.dart는 앞에서 정의된 Book book =Book ()에서의 book 다르게 정의 된건가요??









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