Files
2022-03-26 18:10:17 +08:00

53 lines
1.6 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
/// create by 张风捷特烈 on 2020/9/21
/// contact me by email 1981462002@qq.com
/// 说明: 230 DefaultTabController 默认Tab控制器 在使用TabBar和TabBarView时需要同一个控制器实现页签和页面的控制。DefaultTabController会在未指定控制器时提供默认控制器简化使用。
// {
// "widgetId": 230,
// "name": 'DefaultTabController基本使用',
// "priority": 1,
// "subtitle":
// "【length】 : 页签数量 【int】\n"
// "【initialIndex】 : 初始页签索引 【int】\n"
// "【child】 : 组件 【Widget】",
// }
class DefaultTabControllerDemo extends StatelessWidget {
final List<Tab> tabs = const [
Tab(text: '青眼白龙'),
Tab(text: '黑魔术师'),
Tab(text: '混沌战士'),
];
const DefaultTabControllerDemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return SizedBox(
height: 300,
child: DefaultTabController(
length: tabs.length,
child: Scaffold(
appBar: AppBar(
title: const Text("DefaultTabController"),
bottom: TabBar(
tabs: tabs,
),
),
body: TabBarView(
children: tabs.map((Tab tab) {
return Center(
child: Text(
'${tab.text}',
style: const TextStyle(fontSize: 20),
),
);
}).toList(),
),
),
),
);
}
}