Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created January 15, 2020 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlid/15e13af5af37e26bc632b3197fd3344e to your computer and use it in GitHub Desktop.
Save ryanlid/15e13af5af37e26bc632b3197fd3344e to your computer and use it in GitHub Desktop.
顶部选项卡示例 DefaultTabController
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