Switch가 제대로 실행이 안됩니다.(Flutter)

조회수 636회

안녕하세요. Flutter에서 GetX를 이용한 Youtube 클론 코딩을 하고 있는데요. Switch문을 활용하여 GetX BottomSheet로 Route를 하는데 적용이 안되고 break하여 코드가 적용됩니다. 관련 영상에서의 코드와 똑같은데요.

유튜브링크

코드는 다음과 같습니다.

//
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:youtube_clone_app/src/components/youtube_bottom_Sheet.dart';
import 'package:youtube_clone_app/src/pages/explore.dart';
import 'package:youtube_clone_app/src/pages/home.dart';
import 'package:youtube_clone_app/src/pages/library.dart';
import 'package:youtube_clone_app/src/pages/subscribe.dart';
import '../src/controller/app_controller.dart';

class App extends GetView<AppController> {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Obx(() {
        switch (RouteName.values[controller.currentIndex.value]) {
          case RouteName.Home:
            return Home();
            break;
          case RouteName.Explore:
            return Explore();
            break;
          case RouteName.Subscribe:
            return Subscribe();
            break;
          case RouteName.Library:
            return Library();
            break;
          case RouteName.Add:  // 이 부분이 아래 Container로 나옵니다.
            break;
        }
        return Container();
      }),
      bottomNavigationBar: Obx(
        () => BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: controller.currentIndex.value,      
          showSelectedLabels: true,
          selectedItemColor: Colors.black,
          onTap: controller.currentIndex,   
          items: [
            BottomNavigationBarItem(
              icon: SvgPicture.asset('assets/svg/icons/home_off.svg'),
              activeIcon: SvgPicture.asset('assets/svg/icons/home_on.svg'),
              label: "홈",
            ),
            BottomNavigationBarItem(
              icon: SvgPicture.asset(
                'assets/svg/icons/compass_off.svg',
                width: 22,
              ),
              activeIcon: SvgPicture.asset(
                'assets/svg/icons/compass_on.svg',
                width: 22,
              ),
              label: "탐색",
            ),
            BottomNavigationBarItem(
              icon: Padding(
                padding: EdgeInsets.only(top: 8.0),
                child: SvgPicture.asset(
                  'assets/svg/icons/plus.svg',
                  width: 35,
                ),
              ),
              label: "",
            ),
            BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/svg/icons/subs_off.svg"),
              activeIcon: SvgPicture.asset("assets/svg/icons/subs_on.svg"),
              label: "구독",
            ),
            BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/svg/icons/library_off.svg"),
              activeIcon: SvgPicture.asset("assets/svg/icons/library_on.svg"),
              label: "보관함",
            ),
          ],
        ),
      ),
    );
  }
}

//
import 'package:get/get.dart';
import 'package:youtube_clone_app/src/components/youtube_bottom_Sheet.dart';

enum RouteName { Home, Explore, Add, Subscribe, Library }

class AppController extends GetxService {
  static AppController get to => Get.find();
  RxInt currentIndex = 0.obs;

// 아래처럼 RouteName.Add 일 시에 Get.bottomSheet가 실행이 안되고 ,
// Container가 뜹니다.

  void changePageIndex(int index) {
    if (RouteName.values[index] == RouteName.Add) {  
      _showBottomSheet();
    } else {
      currentIndex(index);
    }
  }

  void _showBottomSheet() {
    Get.bottomSheet(YoutubeBottomSheet());
  }
}

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)