Merge pull request #1353 from OffbandMesh/fix/1272-ui-consistency-dev
fix(#1272): UI consistency pass (signal icons, bottom bar, headers, composer, text size)pull/1359/head
commit
b2766e53a1
@ -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,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The bar behind every chat composer: the surface colour with a soft shadow
|
||||
/// above it, the same in direct and channel chat. (#1276)
|
||||
BoxDecoration composerDecoration(BuildContext context) => BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
],
|
||||
);
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/widgets/composer_decoration.dart';
|
||||
|
||||
// #1276: the DM composer drew a hard top border, the channel composer a soft
|
||||
// shadow, so the line above the input looked different in the two chats.
|
||||
void main() {
|
||||
testWidgets('the composer bar has a soft shadow and no border', (
|
||||
tester,
|
||||
) async {
|
||||
late BoxDecoration decoration;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) {
|
||||
decoration = composerDecoration(context);
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(decoration.border, isNull);
|
||||
expect(decoration.boxShadow, isNotEmpty);
|
||||
});
|
||||
|
||||
test('both chats build their composer bar from composerDecoration', () {
|
||||
for (final (path, count) in [
|
||||
('lib/screens/chat_screen.dart', 2),
|
||||
('lib/screens/channel_chat_screen.dart', 1),
|
||||
]) {
|
||||
final src = File(path).readAsStringSync();
|
||||
expect(
|
||||
'composerDecoration(context)'.allMatches(src).length,
|
||||
count,
|
||||
reason: path,
|
||||
);
|
||||
expect(src.contains('Border(top: BorderSide('), isFalse, reason: path);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/widgets/translated_message_content.dart';
|
||||
|
||||
// #1277: a plain message rendered through flutter_linkify, which fixes its
|
||||
// text scale at 1.0; a message with an @-mention rendered through Text.rich,
|
||||
// which follows the system text size. On a phone with a non-default text
|
||||
// size the two came out at different sizes.
|
||||
|
||||
/// A non-linear scaler, like Android 14 font scaling: +6 at every size.
|
||||
class _PlusSix extends TextScaler {
|
||||
const _PlusSix();
|
||||
@override
|
||||
double scale(double fontSize) => fontSize + 6;
|
||||
@override
|
||||
double get textScaleFactor => 1.5;
|
||||
@override
|
||||
bool operator ==(Object other) => other is _PlusSix;
|
||||
@override
|
||||
int get hashCode => 6;
|
||||
}
|
||||
|
||||
const _fontSize = 16.0;
|
||||
|
||||
Future<void> _pump(WidgetTester tester, String text, TextScaler scaler) =>
|
||||
tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
builder: (context) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(textScaler: scaler),
|
||||
child: Scaffold(
|
||||
body: TranslatedMessageContent(
|
||||
displayText: text,
|
||||
style: const TextStyle(fontSize: _fontSize),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// The size the plain-message widget will draw [_fontSize] at.
|
||||
double _plainSize(WidgetTester tester) {
|
||||
final linkify = find.byWidgetPredicate(
|
||||
(w) => w is Linkify || w is SelectableLinkify,
|
||||
);
|
||||
final w = tester.widget(linkify);
|
||||
final factor = w is Linkify
|
||||
? w.textScaleFactor
|
||||
: (w as SelectableLinkify).textScaleFactor;
|
||||
return _fontSize * factor;
|
||||
}
|
||||
|
||||
/// The size the mention-message paragraph draws [_fontSize] at.
|
||||
double _mentionSize(WidgetTester tester) {
|
||||
final paragraph = tester
|
||||
.renderObjectList<RenderParagraph>(find.byType(RichText))
|
||||
.firstWhere((p) => p.text.toPlainText().contains('hello'));
|
||||
return paragraph.textScaler.scale(_fontSize);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final scaler in [const TextScaler.linear(1.5), const _PlusSix()]) {
|
||||
testWidgets('plain and mention messages scale alike ($scaler)', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, 'hello world', scaler);
|
||||
final plain = _plainSize(tester);
|
||||
|
||||
await _pump(tester, '@[Bob] hello world', scaler);
|
||||
final mention = _mentionSize(tester);
|
||||
|
||||
expect(mention, scaler.scale(_fontSize));
|
||||
expect(plain, closeTo(mention, 0.001));
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||
import 'package:meshcore_open/widgets/app_shell.dart';
|
||||
import 'package:meshcore_open/widgets/quick_switch_bar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
// #1274: the bar was a frosted BackdropFilter over a transparent background.
|
||||
// Nothing was drawn behind it, so the blur only showed where it sampled the
|
||||
// content above its top edge, as a glow over the light map.
|
||||
void main() {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('the bar is opaque with no blur ($brightness)', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.blue,
|
||||
brightness: brightness,
|
||||
),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: Scaffold(
|
||||
body: const SizedBox.expand(),
|
||||
bottomNavigationBar: QuickSwitchBar(
|
||||
selectedIndex: 2,
|
||||
onDestinationSelected: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(BackdropFilter), findsNothing);
|
||||
final surface = tester.widget<Material>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.byType(Material),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(surface.color, isNotNull);
|
||||
expect(surface.color!.a, 1.0);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('in the shell, the bar paints down under the bottom inset', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.padding = const FakeViewPadding(bottom: 34);
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
await tester.pumpWidget(
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => UiViewStateService(),
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: AppShell(
|
||||
isTopLevel: true,
|
||||
selectedIndex: 2,
|
||||
onDestinationSelected: (_) {},
|
||||
body: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final surface = find
|
||||
.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.byType(Material),
|
||||
)
|
||||
.first;
|
||||
expect(tester.getRect(surface).bottom, 800);
|
||||
expect(tester.getRect(surface).height, greaterThanOrEqualTo(60 + 34));
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:meshcore_open/widgets/signal_ui.dart';
|
||||
import 'package:meshcore_open/widgets/snr_indicator.dart';
|
||||
|
||||
// #1273: the signal glyph switched from a triangle at the top tier to bars
|
||||
// below it, and the two lowest tiers shared one glyph.
|
||||
void main() {
|
||||
final family = Symbols.signal_cellular_4_bar.fontFamily;
|
||||
|
||||
test('every tier has its own glyph, all from one family', () {
|
||||
final icons = [for (var t = 0; t < 5; t++) signalUiForStrengthTier(t).icon];
|
||||
expect(icons.toSet().length, 5);
|
||||
for (final icon in icons) {
|
||||
expect(icon.fontFamily, family);
|
||||
}
|
||||
});
|
||||
|
||||
test('no reading uses the same family', () {
|
||||
expect(snrUiFromSNR(null, 10).icon.fontFamily, family);
|
||||
});
|
||||
|
||||
testWidgets('SignalIcon draws the glyph filled', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: SignalIcon(Symbols.signal_cellular_2_bar, color: Colors.amber),
|
||||
),
|
||||
);
|
||||
expect(tester.widget<Icon>(find.byType(Icon)).fill, 1);
|
||||
});
|
||||
|
||||
test('no screen draws a signal glyph outside SignalIcon', () {
|
||||
final offenders = <String>[];
|
||||
final pattern = RegExp(
|
||||
r'Icons\.signal_cellular|\bIcon\(\s*(snrUi|signalUi)\.icon',
|
||||
);
|
||||
for (final f in Directory('lib').listSync(recursive: true)) {
|
||||
if (f is! File || !f.path.endsWith('.dart')) continue;
|
||||
if (pattern.hasMatch(f.readAsStringSync())) offenders.add(f.path);
|
||||
}
|
||||
expect(offenders, isEmpty);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue