Unverified Commit cf3ed1ee authored by Shashi's avatar Shashi Committed by GitHub

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
parent 660c5741
......@@ -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 }) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment