Dart오류 Failed assertion: line 1972 pos 12: 'hasSize'

돌리의 하루·2024년 1월 30일
post-thumbnail

문제는 이 부분에서 발생했다

body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextField(
                decoration: InputDecoration(
                    hintText: '제목 입력하기',
                    border: OutlineInputBorder(),
                    prefixIcon: Icon(Icons.search)),
              ),
            ),
              child: ListView.builder(
                itemCount: 10,
                itemBuilder: (BuildContext context, int index) {
                  return Text('List');
                },
              ),
          ],
        ),

구글링 후 도움이 되는 stackoverflow 글을 찾아 오류를 해결했다.
이 경우에는 제한된 높이가 없어서 무한대의 높이를 가지기에 생기는 오류였다.

  1. shrinkWrap:true를 쓰거나,
  2. sizedBox나 Container로 감싸준 후 width와 height을 주면 된다.
body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextField(
                decoration: InputDecoration(
                    hintText: '영화 제목 입력하기',
                    border: OutlineInputBorder(),
                    prefixIcon: Icon(Icons.search)),
              ),
            ),
            Container(
              height: 50,
              width: 50,
              child: ListView.builder(
                itemCount: 10,
                itemBuilder: (BuildContext context, int index) {
                  return Text('List');
                },
              ),
            ),
          ],
        ),

해결완 :>

profile
진화중인 돌리입니다 :>