fix(#1275): one app-bar title style on every screen
Ten screens built their two-line header by hand with different sizes (titles 24 / 22 / 18 bold / 16, subtitles 11 / 12 / 14), and eleven more shrank a long title to fit (AdaptiveAppBarTitle) instead of cutting it off. A new AppBarTitle gives every app bar the app bar's own title style and a 14 normal subtitle, cut off with an ellipsis when long. It replaces AdaptiveAppBarTitle, which is removed. The DM subtitle loses its dotted underline and tap: the full path is reached from Path Management. Regression test app_bar_title_test.dart: sizes, no shrink-to-fit, every AppBar title in lib goes through AppBarTitle or plain Text with no hard-coded size, and no dotted underline in the DM header. The two source guards fail against dev. Epic: #1272 Agent: StormyElk (session 088ce922)pull/1353/head
parent
e4e0228938
commit
074d186c09
@ -1,17 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AdaptiveAppBarTitle extends StatelessWidget {
|
||||
final String text;
|
||||
|
||||
const AdaptiveAppBarTitle(this.text, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) => SizedBox(
|
||||
width: constraints.maxWidth,
|
||||
child: FittedBox(fit: BoxFit.scaleDown, child: Text(text, maxLines: 1)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The two-line app-bar title: the title in the app bar's own style, and a
|
||||
/// subtitle under it. Every screen with a subtitle uses this, so the sizes
|
||||
/// cannot drift apart again. (#1275)
|
||||
class AppBarTitle extends StatelessWidget {
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
|
||||
static const subtitleStyle = TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.normal,
|
||||
);
|
||||
|
||||
const AppBarTitle(this.title, {super.key, this.subtitle});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sub = subtitle;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(title, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
if (sub != null && sub.isNotEmpty)
|
||||
Text(
|
||||
sub,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: subtitleStyle,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/widgets/app_bar_title.dart';
|
||||
|
||||
// #1275: two-line app-bar headers were built by hand on each screen with
|
||||
// different sizes (titles 24 / 22 / 18 bold / 16, subtitles 11 / 12 / 14),
|
||||
// and 11 screens shrank a long title to fit instead of cutting it off.
|
||||
void main() {
|
||||
testWidgets('title takes the app bar style, subtitle is 14 normal', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const AppBarTitle('Alpha', subtitle: 'Beta')),
|
||||
),
|
||||
),
|
||||
);
|
||||
final appBarStyle = Theme.of(
|
||||
tester.element(find.byType(AppBar)),
|
||||
).textTheme.titleLarge!;
|
||||
|
||||
final title = tester.renderObject<RenderParagraph>(find.text('Alpha'));
|
||||
final subtitle = tester.renderObject<RenderParagraph>(find.text('Beta'));
|
||||
expect(title.text.style!.fontSize, appBarStyle.fontSize);
|
||||
expect(subtitle.text.style!.fontSize, 14);
|
||||
expect(subtitle.text.style!.fontWeight, FontWeight.normal);
|
||||
expect(subtitle.text.style!.decoration, isNot(TextDecoration.underline));
|
||||
expect(find.byType(FittedBox), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a long title keeps its size and is cut off', (tester) async {
|
||||
tester.view.physicalSize = const Size(320, 640);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: AppBarTitle('W' * 60, subtitle: 'x' * 90)),
|
||||
),
|
||||
),
|
||||
);
|
||||
final title = tester.renderObject<RenderParagraph>(find.text('W' * 60));
|
||||
expect(title.didExceedMaxLines, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
test('every app bar title goes through AppBarTitle or plain Text', () {
|
||||
final offenders = <String>[];
|
||||
final appBar = RegExp(r'\bAppBar\(');
|
||||
final title = RegExp(r'\btitle:\s*');
|
||||
for (final f in Directory('lib').listSync(recursive: true)) {
|
||||
if (f is! File || !f.path.endsWith('.dart')) continue;
|
||||
final src = f.readAsStringSync();
|
||||
for (final m in appBar.allMatches(src)) {
|
||||
final window = src.substring(m.end, (m.end + 400).clamp(0, src.length));
|
||||
final t = title.firstMatch(window);
|
||||
if (t == null) continue;
|
||||
final value = window.substring(t.end);
|
||||
final head = value.substring(0, value.length.clamp(0, 220));
|
||||
// A Consumer wrapper is fine as long as what it builds is AppBarTitle.
|
||||
final consumer = RegExp(r'^Consumer\d?<[^>]+>\(').hasMatch(value);
|
||||
final ok = consumer
|
||||
? src
|
||||
.substring(m.end, (m.end + 1200).clamp(0, src.length))
|
||||
.contains('AppBarTitle(')
|
||||
: RegExp(r'^(const\s+)?(AppBarTitle|Text|Row)\(').hasMatch(value) &&
|
||||
!head.contains('fontSize') &&
|
||||
!head.contains('FittedBox');
|
||||
if (!ok) {
|
||||
final line = '\n'.allMatches(src.substring(0, m.start)).length + 1;
|
||||
offenders.add('${f.path}:$line');
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(offenders, isEmpty);
|
||||
});
|
||||
|
||||
test('no dotted-underline tap targets remain in headers', () {
|
||||
final chat = File('lib/screens/chat_screen.dart').readAsStringSync();
|
||||
expect(chat.contains('TextDecorationStyle.dotted'), isFalse);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue