flutter - Flutter 标签栏动画有一个小故障
问题描述
我创建了一个无状态标签栏DefaultTabController
,我设置unselectedLabelStyle
了较小的 fontSize 和labelStyle
较大的 fontSize。
在选项卡之间切换时的动画有一个小故障。
示例代码(更新):
import 'package:flutter/material.dart';
import 'package:fluttericon/entypo_icons.dart';
import 'package:nixo_exchange/core/widgets/keep_alive_wrapper.dart';
import 'package:nixo_exchange/core/widgets/scroll_glow_remover.dart';
import 'package:nixo_exchange/theme/theme_manager.dart';
class NHeaderTab extends StatelessWidget {
final List<String> tabText;
final List<Widget> children;
final Icon? firstIcon;
final Icon? secondIcon;
final EdgeInsetsGeometry? labelPadding;
final Widget? divider;
final Function(int index)? onTap;
const NHeaderTab({
required this.tabText,
required this.children,
this.onTap,
this.firstIcon,
this.secondIcon,
this.labelPadding,
this.divider,
Key? key,
}) : assert(tabText.length == 3, 'Only accept 3 tab'),
assert(tabText.length == children.length,
'Number of tab must equal to number of children'),
super(key: key);
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: tabText.length,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.center,
end: Alignment.centerRight,
colors: [
Colors.white,
Colors.white.withOpacity(0.0),
],
stops: [.85, 1.0],
).createShader(bounds);
},
child: ScrollGlowRemover(
child: TabBar(
isScrollable: true,
indicatorColor: Colors.transparent,
labelPadding: labelPadding,
onTap: (index) {
if (onTap != null) onTap!(index);
},
unselectedLabelStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: ThemeManager.of(context).fontSize.large,
// color: Colors.red,
),
labelStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: ThemeManager.of(context).fontSize.large2x,
),
labelColor:
ThemeManager.of(context).color.headerLabelColor,
unselectedLabelColor: ThemeManager.of(context)
.color
.headerUnselectedLabelColor,
physics: const AlwaysScrollableScrollPhysics(),
tabs: List<Tab>.generate(
tabText.length, (i) => Tab(text: tabText[i])),
),
),
),
),
const SizedBox(width: 3),
GestureDetector(
onTap: () {
if (onTap != null) onTap!(tabText.length);
},
behavior: HitTestBehavior.opaque,
child: firstIcon ?? const Icon(Icons.addchart),
),
const SizedBox(width: 10),
GestureDetector(
onTap: () {
if (onTap != null) onTap!(tabText.length + 1);
},
behavior: HitTestBehavior.opaque,
child: secondIcon ?? const Icon(Entypo.search),
),
],
),
divider ??
Divider(
height: 0,
thickness: 0.05,
color: ThemeManager.of(context).color.dividerColor,
),
Expanded(
child: KeepAliveWrapper(
child: TabBarView(
children: children,
),
),
),
],
),
);
}
}
解决方案
推荐阅读
- c - 用 0 初始化一个整数与不在 C 中初始化它
- javascript - 如何将 Rails 视图的 javascript 代码放入 assets/javascript 文件夹?
- javascript - 当 input[type="date"] 成为焦点时如何显示日历弹出窗口
- rust - 为什么我需要 mod 关键字来访问 Rust 相同级别的文件中的结构?
- jquery - 当服务器端数据发生变化时自动更新 jQuery DataTables
- javascript - d3fc.js d3fc JavaScript 中线条系列的设置类
- python - 梯度下降算法,梯度步进函数
- bash - 排序在 bash 中无法正常工作
- maven - 为什么某些 maven 依赖项以颜色显示并且没有得到解决?
- php - 令牌未在 mysql db 中更新