我有这样的代码,它会得到屏幕宽度来计算和设置标签自适应宽度accordingto screensize.它在调试模式下工作正常,但在释放模式下,标签总是发现可以滚动与大amoung的宽度. isScrollable
属性的Tabbar被设置为true
提供所需的宽度标签.
final double screenWidth = Data.screen.width;
@override
void initState() {
super.initState();
_tabController = TabController(vsync: this, length: 4);
_tabController.addListener(_handleTabSelection);
tabWidth = screenWidth / 4.8;
}
@override
Widget build(BuildContext context) {
List<Widget> myTabs = [
const HomePageTab(
icon: Icons.groups_rounded,
),
SizedBox(
width: tabWidth,
child: const HomePageTab(
title: 'Chats',
),
),
SizedBox(
width: tabWidth,
child: const HomePageTab(
title: 'Status',
),
),
SizedBox(
width: tabWidth,
child: const HomePageTab(
title: 'Calls',
),
),
];
.
In release mode
In Debug mode
1条答案
按热度按时间rm5edbpk1#
使用
var screenSize = MediaQuery.of(context).size