Unverified Commit 1546f41e authored by Per Classon's avatar Per Classon Committed by GitHub

Add width constraints for FlexibleSpaceBar.title in its expanded state, so...

Add width constraints for FlexibleSpaceBar.title in its expanded state, so that overflow of long titles can be handled (#51335)
parent 31df1d45
......@@ -394,7 +394,15 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
alignment: titleAlignment,
child: DefaultTextStyle(
style: titleStyle,
child: title,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Container(
width: constraints.maxWidth / scaleValue,
alignment: titleAlignment,
child: title,
);
}
),
),
),
),
......
......@@ -117,6 +117,57 @@ void main() {
expect(clipRect.size.height, minExtent);
});
// This is a regression test for https://github.com/flutter/flutter/issues/14227
testWidgets('FlexibleSpaceBar sets width constraints for the title', (WidgetTester tester) async {
const double titleFontSize = 20.0;
const double height = 300.0;
double width;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(
builder: (BuildContext context) {
width = MediaQuery.of(context).size.width;
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: height,
pinned: true,
stretch: true,
flexibleSpace: FlexibleSpaceBar(
titlePadding: EdgeInsets.zero,
title: Text(
'X' * 2000,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: titleFontSize),
),
centerTitle: false,
),
),
],
);
}
),
),
),
);
// The title is scaled and transformed to be 1.5 times bigger, when the
// FlexibleSpaceBar is fully expanded, thus we expect the width to be
// 1.5 times smaller than the full width. The height of the text is the same
// as the font size, with 10 dps bottom margin.
expect(
tester.getRect(find.byType(Text)),
Rect.fromLTRB(
0,
height - titleFontSize - 10,
(width / 1.5).floorToDouble(),
height - 10,
),
);
});
testWidgets('FlexibleSpaceBar test titlePadding defaults', (WidgetTester tester) async {
Widget buildFrame(TargetPlatform platform, bool centerTitle) {
return MaterialApp(
......
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