Add font: own web file chooser, so a picked font is never dropped silently

file_picker's web picker treated the window regaining focus as a cancel when
the files arrived more than 500 ms later, so a real dialog could return an
empty pick and Add font did nothing. The web now uses its own file input that
completes only on change or cancel; mobile browsers get no accept filter.
Picker, check and save failures are shown in a dialog, and the row is busy
only after files were chosen.
This commit is contained in:
2026-11-04 20:47:43 +00:00
parent 1d025bebf3
commit 081ae0957d
8 changed files with 361 additions and 32 deletions
@@ -0,0 +1,80 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/theme/custom_fonts/custom_font_draft.dart';
import 'package:pipelines_app/ui/theme/custom_fonts/font_file_picker.dart';
FontFileSource _source(
String name, {
int? size,
Future<Uint8List?> Function()? read,
}) => FontFileSource(
name: name,
size: size,
read: read ?? () async => Uint8List.fromList(<int>[1, 2, 3]),
);
Matcher _rejected(String message) => throwsA(
isA<CustomFontRejected>().having((e) => e.message, 'message', message),
);
void main() {
test('an empty selection is a cancel', () async {
expect(await readFontSelection(const <FontFileSource>[]), isNull);
});
test('chosen files come back with their bytes, in order', () async {
final files = await readFontSelection(<FontFileSource>[
_source('A.ttf', size: 3),
_source('B.otf'),
]);
expect(files!.map((f) => f.name), <String>['A.ttf', 'B.otf']);
expect(files.first.bytes, <int>[1, 2, 3]);
});
test('a file whose bytes the host cannot provide is refused', () async {
await expectLater(
readFontSelection(<FontFileSource>[
_source('A.ttf', read: () async => null),
]),
_rejected('“A.ttf” could not be read.'),
);
});
test('a read that throws is refused by name, not swallowed', () async {
await expectLater(
readFontSelection(<FontFileSource>[
_source('A.ttf', read: () async => throw StateError('NotReadable')),
]),
_rejected('“A.ttf” could not be read.'),
);
});
test('a file over the limit is refused before it is read', () async {
var read = false;
await expectLater(
readFontSelection(<FontFileSource>[
_source(
'Huge.ttf',
size: CustomFontLimits.maxFileBytes + 1,
read: () async {
read = true;
return Uint8List(0);
},
),
]),
_rejected('“Huge.ttf” is larger than 10 MB.'),
);
expect(read, isFalse);
});
test('another file type passes through for inspect to refuse', () async {
final files = await readFontSelection(<FontFileSource>[
_source('photo.png'),
]);
expect(
() => CustomFontDraft.inspect(files!),
_rejected('“photo.png” is not a .ttf or .otf font file.'),
);
});
}