You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansu_ui/lib/bar/as_tabbar.dart

98 lines
2.4 KiB

4 years ago
import 'package:ansu_ui/badge/as_badge.dart';
4 years ago
import 'package:ansu_ui/bar/as_tab_indicator.dart';
4 years ago
import 'package:ansu_ui/bar/as_tabbar_item.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:ansu_ui/styles/as_colors.dart';
4 years ago
import 'package:ansu_ui/extension/string_extension.dart';
4 years ago
/// ## 安速Tabbar
///
/// [items]
///
/// [controller] see more TabController
class ASTabBar extends StatefulWidget implements PreferredSizeWidget {
///items
final List<String> items;
4 years ago
final List<ASTabBarItem> tabItems;
/// TabController
final TabController controller;
///可滚动
final bool isScrollable;
ASTabBar(
{Key key,
@required this.items,
@required this.controller,
this.isScrollable = false})
4 years ago
: tabItems = null,
super(key: key);
4 years ago
/// ## TabBar with tag
///```dart
/// ASTabBar.tag(
/// isScrollable: true,
/// tabItems: [
/// ASTabBarItem(title:'Tab1',tag:'12'),
/// ASTabBarItem(title:'Tab2'),
/// ],
/// controller: _tabController4,
/// )
///```
///
4 years ago
ASTabBar.tag(
{Key key,
@required this.tabItems,
@required this.controller,
this.isScrollable = false})
: items = null,
super(key: key);
@override
_ASTabBarState createState() => _ASTabBarState();
@override
Size get preferredSize => Size.fromHeight(46);
}
class _ASTabBarState extends State<ASTabBar> {
4 years ago
bool get isTag => widget.items?.isEmpty ?? true;
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.center,
child: TabBar(
isScrollable: widget.isScrollable,
controller: widget.controller,
4 years ago
tabs: isTag
? widget.tabItems.map((e) {
return Tab(
child: ASBadge(
child: e.title.text,
tag: e.tag,
),
);
}).toList()
: widget.items
.map((e) => Tab(
child: e.text,
))
.toList(),
labelStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
unselectedLabelStyle: TextStyle(
fontWeight: FontWeight.normal,
),
labelColor: kTextColor,
unselectedLabelColor: kTextSubColor,
indicatorSize: TabBarIndicatorSize.label,
indicatorPadding: EdgeInsets.zero,
indicator: ASTabIndicator(),
),
);
}
}