Disable Swiping Tabbar
Complete Code For Disable Swiping Tabbar In Flutter
Main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'APP',
home: DisableSwipingTabbar(),
);
}
}
class DisableSwipingTabbar extends StatefulWidget {
@override
DisableSwipingTabbarState createState() {
return new DisableSwipingTabbarState();
}
}
class DisableSwipingTabbarState extends State<DisableSwipingTabbar>
with SingleTickerProviderStateMixin {
TabController _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(
length: 2,
vsync: this,
initialIndex: 0,
)..addListener(() {
setState(() {
_tabController.index = 0;
});
});
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
title: Text("Disable onTap Tabbar"),
bottom: TabBar(
controller: _tabController,
tabs: <Widget>[
Tab(
text: "First Tab",
),
Tab(
text: "Second Tab",
),
],
),
),
body: TabBarView(
controller: _tabController,
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
Center(
child: Text("First Tab"),
),
Center(
child: Text("Second Tab"),
),
],
),
);
}
}