• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    미해결

데이터의 실제 구조를 볼려면 어떻게 해야되나용?

21.04.27 17:51 작성 조회수 136

0

안녕하세요

Widget _buildBody() {
return StreamBuilder(
stream: FirebaseFirestore.instance.collection('postCompany').snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot){
if(!snapshot.hasData) return Center(child: Text('사진이 없습니다.', style: TextStyle(fontSize: 30),),);
else {
var items = snapshot.data.docs ?? [];
print('this is items : ${items}');
return GridView.builder(gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, childAspectRatio: 1.0, mainAxisSpacing: 1.0, crossAxisSpacing: 1.0), itemCount: items.length, itemBuilder: (context, index){
return _buildListItem(context, items[index]);
});
}
});

해당 부분에서

실제 items에 데이터가 어떻게 생겼는지 궁금한데

이럴때는 어떻게 print문으로 데이터의 구조를 볼 수있을까요?

실제 items라고 치면

this is items : Instance of 'QueryDocumentSnapshot',  Instance of 'QueryDocumentSnapshot'

라고 나오고

items[0]으로 쳐도

this is items : Instance of 'QueryDocumentSnapshot'

라고만 나와서요!!

답변 2

·

답변을 작성해보세요.

1

제공되는 QueryDocumentSnapshot 객체의 toString() 정의가 안 되어 있어서 print()로는 확인이 어려울 것 같습니다.

해당 위치에서 라인넘버 쪽 클릭을 하여 브레이크 포인트를 설정하고 실행 버튼 오른쪽 debug 모드로 실행하시면 해당 위치에서 멈추게 됩니다.

디버그 화면에서 해당 변수에 마우스를 올려보면 내부를 탐색할 수 있게됩니다.

디버그 모드를 활용해 보세요.

0

김동혁님의 프로필

김동혁

질문자

2021.04.28

고맙습니다. 내부구조확인해보니 실제로 map 형태로 키와 밸류값을 확인했습니다.!!