Created
January 15, 2020 16:42
-
-
Save ryanlid/15e13af5af37e26bc632b3197fd3344e to your computer and use it in GitHub Desktop.
顶部选项卡示例 DefaultTabController
This file contains hidden or 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 { | |
final List<Tab> tab = <Tab>[ | |
Tab(text: "选项一"), | |
Tab(text: "选项二"), | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: "MaterialApp示例", | |
home: DefaultTabController( | |
length: tab.length, | |
child: Scaffold( | |
appBar: AppBar( | |
title: Text("顶部选项卡示例"), | |
// 添加选项卡按钮 | |
bottom: TabBar( | |
tabs: tab, | |
), | |
), | |
body: TabBarView( | |
children: tab.map((Tab tab) { | |
return Center( | |
child: Text(tab.text), | |
); | |
}).toList(), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment