[flutter] 플러터 BottomSheet 사용 방법

BottomSheet란?

BottomSheet는 화면 하단에서 표시되는 옵션 메뉴이며, ModalBottomSheet와 PersistentBottomSheet 두 가지 유형으로 사용할 수 있습니다. ModalBottomSheet는 일시적으로 사용되며 사용자가 선택을 완료하면 사라지는 형태입니다. 반면, PersistentBottomSheet는 영구적으로 화면 하단에 남아있는 형태로 사용자가 필요할 때마다 열고 닫을 수 있습니다.

Flutter에서 BottomSheet 사용 방법

Flutter에서 BottomSheet를 사용하려면 Scaffold 위젯 안에 Scaffold.of(context).showBottomSheet() 메서드를 호출하여 BottomSheet를 표시할 수 있습니다. 아래는 간단한 예시입니다.

void _showBottomSheet(BuildContext context) {
  showModalBottomSheet(
    context: context,
    builder: (BuildContext context) {
      return Container(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            ListTile(
              leading: Icon(Icons.photo),
              title: Text('사진 선택'),
              onTap: () {
                // 작업 수행
              },
            ),
            ListTile(
              leading: Icon(Icons.video_call),
              title: Text('동영상 선택'),
              onTap: () {
                // 작업 수행
              },
            ),
          ],
        ),
      );
    },
  );
}

위 예시는 Scaffold의 build 메서드 안에서 _showBottomSheet()을 호출하여 BottomSheet를 띄우는 예시입니다.

이처럼 Flutter에서 BottomSheet를 사용하면 사용자에게 다양한 옵션을 제공하고, 중요한 정보를 하단에서 간편하게 표시할 수 있습니다.

필요한 경우 ModalBottomSheet와 PersistentBottomSheet 중 필요한 것을 선택하여 사용할 수 있으며, 각각의 유형에 따라 적절한 사용 방식을 선택하여 구현할 수 있습니다.