Fix BottomNavigationBarItem label overflow (#120206)
This PR wraps the `label` with `IntrinsicWidth` and then `Flexible` which allows DefaulTextStyle `TextOverflow.ellipsis` to work. Wrapping `label` directly with `Flexible` brings more space between `icon` and `label`. `IntrinsicWidth` fixes this by giving reasonable width. Fixes #112163
This commit is contained in:
@@ -647,7 +647,14 @@ class _Tile extends StatelessWidget {
|
||||
heightFactor: 1,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[icon, const SizedBox(width: 8), label],
|
||||
children: <Widget>[
|
||||
icon,
|
||||
const SizedBox(width: 8),
|
||||
// Flexible lets the overflow property of
|
||||
// label to work and IntrinsicWidth gives label a
|
||||
// resonable width preventing extra space before it.
|
||||
Flexible(child: IntrinsicWidth(child: label))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3122,6 +3122,59 @@ void main() {
|
||||
expect(tester.getRect(find.byKey(icon0)), Rect.fromLTRB(firstItemLeft, iconTop, firstItemLeft + iconWidth, iconTop + iconHeight));
|
||||
expect(tester.getRect(find.byKey(icon1)), Rect.fromLTRB(secondItemLeft, iconTop, secondItemLeft + iconWidth, iconTop + iconHeight));
|
||||
}, skip: kIsWeb && !isCanvasKit); // https://github.com/flutter/flutter/issues/99933
|
||||
|
||||
testWidgets('BottomNavigationBar linear landscape layout label RenderFlex overflow',(WidgetTester tester) async {
|
||||
//Regression test for https://github.com/flutter/flutter/issues/112163
|
||||
|
||||
tester.view.physicalSize = const Size(540, 340);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return Scaffold(
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
type: BottomNavigationBarType.fixed,
|
||||
landscapeLayout: BottomNavigationBarLandscapeLayout.linear,
|
||||
items: const <BottomNavigationBarItem>[
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home_rounded),
|
||||
label: 'Home Challenges',
|
||||
backgroundColor: Colors.grey,
|
||||
tooltip: '',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.date_range_rounded),
|
||||
label: 'Daily Challenges',
|
||||
backgroundColor: Colors.grey,
|
||||
tooltip: '',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.wind_power),
|
||||
label: 'Awards Challenges',
|
||||
backgroundColor: Colors.grey,
|
||||
tooltip: '',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.bar_chart_rounded),
|
||||
label: 'Statistics Challenges',
|
||||
backgroundColor: Colors.grey,
|
||||
tooltip: '',
|
||||
),
|
||||
],
|
||||
));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
find.byType(MaterialApp),
|
||||
matchesGoldenFile('bottom_navigation_bar.label_overflow.png'),
|
||||
);
|
||||
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
});
|
||||
}
|
||||
|
||||
Widget boilerplate({ Widget? bottomNavigationBar, required TextDirection textDirection, bool? useMaterial3 }) {
|
||||
|
||||
Reference in New Issue
Block a user