1

i have a layout that if the index of tabView is 0, then show a widget in AppBar. i can do it. But, the problem is when you swipe the tabView fast, the page is bounce.

enter image description here

Can we disable the page bounce? or any other solution? here is my code:

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  TabController _tabController;
  int _currentIndex;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
    _currentIndex = 0;
    _tabController.animateTo(_currentIndex);
    _tabController.addListener(() {
      setState(() {
        _currentIndex = _tabController.index;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Page ${_currentIndex}'),
        bottom: TabBar(
          controller: _tabController,
          tabs: [
            Tab(text: 'One',),
            Tab(text: 'Two',),
            Tab(text: 'Three',),
          ],
        ),
        leading: _currentIndex == 0? Icon(Icons.ac_unit): Container(),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          Container(color: Colors.red,),
          Container(color: Colors.green,),
          Container(color: Colors.blue,),
        ],
      ),
    );
  }

}
Angga Arya S
  • 137
  • 1
  • 11

1 Answers1

0

TabBarView has default physics PageScrollPhysics, you can change it to see which physics works best for you, AlwaysScrollablePhysics might do the trick

M.M.Hasibuzzaman
  • 1,015
  • 5
  • 10
  • i have tried `/// /// AlwaysScrollableScrollPhysics /// BouncingScrollPhysics /// ClampingScrollPhysics /// FixedExtentScrollPhysics /// NeverScrollableScrollPhysics /// PageScrollPhysics /// RangeMaintainingScrollPhysics ///` but still not working – Angga Arya S Mar 29 '21 at 09:02