Created
May 14, 2019 16:10
-
-
Save Andrious/123790ce092d9776bae1bc2643108ee9 to your computer and use it in GitHub Desktop.
Demo. the App Bar Tabs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
MyApp({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final title = 'Silver AppBar With ToolBar'; | |
return MaterialApp( | |
title: title, | |
home: Scaffold( | |
// No appbar provided to the Scaffold, only a body with a | |
// CustomScrollView | |
body: SilverAppBarWithTabBarScreen(title: title), | |
), | |
); | |
} | |
} | |
class SilverAppBarWithTabBarScreen extends StatefulWidget { | |
final String title; | |
SilverAppBarWithTabBarScreen({Key key, this.title}):super(key: key); | |
@override | |
_SilverAppBarWithTabBarState createState() => _SilverAppBarWithTabBarState(); | |
} | |
class _SilverAppBarWithTabBarState extends State<SilverAppBarWithTabBarScreen> | |
with SingleTickerProviderStateMixin { | |
TabController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = TabController(length: 3, vsync: this); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: CustomScrollView( | |
slivers: <Widget>[ | |
SliverAppBar( | |
title: Text(widget.title), | |
pinned: true, | |
expandedHeight: 160.0, | |
bottom: TabBar( | |
tabs: [ | |
Tab(text: 'Tab 1'), | |
Tab(text: 'Tab 2'), | |
Tab(text: 'Tab 3'), | |
], | |
controller: controller, | |
), | |
), | |
SliverFillRemaining( | |
child: TabBarView( | |
controller: controller, | |
children: <Widget>[ | |
Text("Content for Tab 1"), | |
Text("Content for ab 2"), | |
Text("Content for Tab 3"), | |
], | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment