Flutter TabBarView 스와이프 막기 (disable swiping tabs in TabBar flutter)

adbr·2020년 8월 27일
0

solution

TabBarView(
        physics: NeverScrollableScrollPhysics(),
        controller: tabcontroler,
        children: <Widget>[
          Container(color: Colors.red),
          Container(color: Colors.green),
          Container(color: Colors.blue),
        ],
      ),
  1. BouncingScrollPhysics () : 목록의 끝 / 시작시 bouncing 스크롤
  2. NeverScrollableScrollPhysics () : 탭 변경 중지 or 목록 스크롤 중지 or 페이지 뷰의 페이지 변경 중지
  3. ClampingScrollPhysics () : 정상 동작


full code

class HomePage extends StatefulWidget {
  
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  final List<Widget> _pages = [];

  
  void initState() {
    super.initState();

    _pages.add(Page1());
    _pages.add(Page2());
    _pages.add(Page3());
  }

  
  Widget build(BuildContext context) {
    
    return DefaultTabController(
      key: _tabKey,
      length: 3,
      child: TabBarView(
        physics: NeverScrollableScrollPhysics(),
        children: _pages,
        controller: _commonsService.tabController,
      ),
    );
  }
}



cf. https://stackoverflow.com/questions/51518393/disable-swiping-tabs-in-tabbar-flutter/51523272

profile
𝙸 𝚊𝚖 𝚊 𝚌𝚞𝚛𝚒𝚘𝚞𝚜 𝚍𝚎𝚟𝚎𝚕𝚘𝚙𝚎𝚛 𝚠𝚑𝚘 𝚎𝚗𝚓𝚘𝚢𝚜 𝚍𝚎𝚏𝚒𝚗𝚒𝚗𝚐 𝚊 𝚙𝚛𝚘𝚋𝚕𝚎𝚖. 🇰🇷👩🏻‍💻

0개의 댓글