Screenshot :
Program :
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:oauth2/oauth2.dart' as oauth2;
void main() {
runApp(new MaterialApp(
title: 'Flutter Tutorial',
home: new TabDream11(),
));
}
class TabDream11 extends StatefulWidget {
@override
_TabDream11State createState() => _TabDream11State();
}
class _TabDream11State extends State<TabDream11>
with SingleTickerProviderStateMixin {
List<String> categories = ["All", "Today"];
TabController tabController;
TextStyle tabStyle = TextStyle(fontSize: 16);
@override
void initState() {
super.initState();
tabController =
TabController(length: categories.length, vsync: this, initialIndex: 0);
}
tabCreate() =>
CustomScrollView(
slivers: <Widget>[
SliverFillRemaining(
child: Scaffold(
backgroundColor: Colors.white70,
appBar: TabBar(
indicatorColor: Colors.blue,
labelColor: Colors.black,
unselectedLabelColor: Colors.black54,
controller: tabController,
isScrollable: false,
tabs: List<Widget>.generate(categories.length, (int index) {
return new Tab(
child: Text(categories[index],
style: TextStyle(
fontWeight: FontWeight.w500, fontSize: 15.0)));
}),
),
body: TabBarView(
controller: tabController,
children: List<Widget>.generate(
categories.length, (int index) {
return new Text(categories[index]);
})),
),
),
],
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter Tab Dynamic'),
),
body: tabCreate());
}
tabName(String name) =>
Tab(
child: Text(
name,
style: tabStyle,
),
);
}