Posts

Showing posts with the label tabs

Segments in Flutter

Im working on a Flutter app and trying to add a segment to my app. Is it possible to achieve it in Flutter. So i would like 2 different widgets for the 2 buttons. It is similar to the TabBar in Flutter or Segment in native apps As you tried, you can acheive it with TabBarView easily. The below code shows a very basic implementation of how it can be acheived. Example: class Example extends StatefulWidget { @override _ExampleState createState() => new _ExampleState(); } class _ExampleState extends State<Example> with SingleTickerProviderStateMixin { // TabController to control and switch tabs TabController _tabController; // Current Index of tab int _currentIndex = 0; @override void initState() { super.initState(); _tabController = new TabController(vsync: this, length: 2, initialIndex: _currentIndex); } @override void dispose() { _tabController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { ...