diff --git a/lib/src/view/more/import_pgn_screen.dart b/lib/src/view/more/import_pgn_screen.dart index 165c48c99..3a89e2b7e 100644 --- a/lib/src/view/more/import_pgn_screen.dart +++ b/lib/src/view/more/import_pgn_screen.dart @@ -18,8 +18,7 @@ import 'package:lichess_mobile/src/widgets/feedback.dart'; /// A provider for picking PGN files. Can be overridden in tests. final pickPgnFileProvider = Provider Function()>((ref) { - return () => - FilePicker.pickFiles(type: FileType.custom, allowedExtensions: ['pgn'], withData: true); + return () => FilePicker.pickFiles(type: FileType.custom, allowedExtensions: ['pgn']); }); class ImportPgnScreen extends StatelessWidget { @@ -131,8 +130,9 @@ class _BodyState extends ConsumerState<_Body> { try { final result = await ref.read(pickPgnFileProvider)(); - if (result != null && result.files.single.bytes != null) { - final content = utf8.decode(result.files.single.bytes!, allowMalformed: true); + if (result != null) { + final bytes = await result.files.single.readAsBytes(); + final content = utf8.decode(bytes, allowMalformed: true); if (mounted) { ImportPgnScreen.handlePgnText(context, content); } diff --git a/pubspec.lock b/pubspec.lock index 9267da5e1..cbed44d5b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -407,10 +407,10 @@ packages: dependency: "direct main" description: name: file_picker - sha256: "51093fc49e4d58935998fb112593c23eda571d14b488388bd41d5d2ba332b26a" + sha256: "0204695694b687b167fd497da5252e9f4aaa162e8d274d6fa1e757380f2a5f46" url: "https://pub.dev" source: hosted - version: "12.0.0-beta.3" + version: "12.0.0-beta.4" file_selector_linux: dependency: transitive description: @@ -625,18 +625,18 @@ packages: dependency: "direct main" description: name: flutter_secure_storage - sha256: "6848263f9744072d0977347c383fb8b57d9780319a6bf5238b5a2866a029de62" + sha256: d2a6ac2df7353f5ca47eb159a5407c1dba7ec48ca0e02dc38c9ff4d29447b261 url: "https://pub.dev" source: hosted - version: "10.2.0" + version: "10.3.0" flutter_secure_storage_darwin: dependency: transitive description: name: flutter_secure_storage_darwin - sha256: "67cd1ff671add31dc13e45194398187a04bb63804b37fa47866afae296d73fcb" + sha256: "82329fa5cdf343773b1b6897dea959105a29f092454259edff92f9f6637e8149" url: "https://pub.dev" source: hosted - version: "0.3.1" + version: "0.3.2" flutter_secure_storage_linux: dependency: "direct overridden" description: @@ -666,10 +666,10 @@ packages: dependency: transitive description: name: flutter_secure_storage_windows - sha256: "8f42f359f187a94dce7a3ab2ec5903d013dddfc7127078ebab19fa244c3840e8" + sha256: "471951813a97006d899db4948acc654a4f28c440083ea08178935ce20b173ec1" url: "https://pub.dev" source: hosted - version: "4.2.1" + version: "4.2.2" flutter_slidable: dependency: "direct main" description: @@ -748,10 +748,10 @@ packages: dependency: "direct main" description: name: home_widget - sha256: b04f99438ad6c5aad80fc9fca1e2e3471bf2a15028f614e4814d2552e13bc2a3 + sha256: "7a32f7d6a3afd542126fb0004acba939a41ee57d874172926212774fbce684d3" url: "https://pub.dev" source: hosted - version: "0.9.1" + version: "0.9.2" hooks: dependency: transitive description: @@ -1802,10 +1802,10 @@ packages: dependency: transitive description: name: win32 - sha256: a1fc9eb9248baa05dfc12ed5b66e377b3e23f095eec078e0371622b9033810d9 + sha256: ba6f4bba816c8d7e3c1580e170f3786d216951cc6b94babc3b814c08d2cb2738 url: "https://pub.dev" source: hosted - version: "6.2.0" + version: "6.3.0" win32_registry: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9fd0b5634..e4d8a10d6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: url: https://github.com/veloce/flutter_dynamic_system_colors.git ref: main fast_immutable_collections: ^11.2.0 - file_picker: ^12.0.0-beta.3 + file_picker: ^12.0.0-beta.4 firebase_core: ^4.9.0 firebase_crashlytics: ^5.2.2 firebase_messaging: ^16.2.2 @@ -49,11 +49,11 @@ dependencies: flutter_markdown: ^0.7.7+1 flutter_native_splash: ^2.4.7 flutter_riverpod: ^3.3.1 - flutter_secure_storage: ^10.2.0 + flutter_secure_storage: ^10.3.0 flutter_slidable: ^4.0.3 flutter_spinkit: ^5.2.2 freezed_annotation: ^3.1.0 - home_widget: ^0.9.1 + home_widget: ^0.9.2 http: ^1.6.0 image_picker: ^1.2.2 intl: ^0.20.2 diff --git a/test/view/more/import_pgn_screen_test.dart b/test/view/more/import_pgn_screen_test.dart index e23ad73db..95a279673 100644 --- a/test/view/more/import_pgn_screen_test.dart +++ b/test/view/more/import_pgn_screen_test.dart @@ -11,6 +11,19 @@ import 'package:lichess_mobile/src/widgets/platform_search_bar.dart'; import '../../test_provider_scope.dart'; +/// A [PlatformFile] that overrides [readAsBytes] to return in-memory bytes, +/// avoiding the need for a real file path in tests. +class _FakePlatformFile extends PlatformFile { + _FakePlatformFile({required super.name, required super.size, required Uint8List fileBytes}) + : _fileBytes = fileBytes, + super(path: ''); + + final Uint8List _fileBytes; + + @override + Future readAsBytes() async => _fileBytes; +} + void _mockClipboard(String text) { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler( SystemChannels.platform, @@ -182,7 +195,7 @@ void main() { final app = await _makeApp( tester, pickResult: FilePickerResult([ - PlatformFile(name: 'game.pgn', size: pgnBytes.length, bytes: pgnBytes), + _FakePlatformFile(name: 'game.pgn', size: pgnBytes.length, fileBytes: pgnBytes), ]), ); await tester.pumpWidget(app); @@ -219,7 +232,7 @@ void main() { final app = await _makeApp( tester, pickResult: FilePickerResult([ - PlatformFile(name: 'games.pgn', size: pgnBytes.length, bytes: pgnBytes), + _FakePlatformFile(name: 'games.pgn', size: pgnBytes.length, fileBytes: pgnBytes), ]), ); await tester.pumpWidget(app); @@ -299,7 +312,7 @@ void main() { final app = await _makeApp( tester, pickResult: FilePickerResult([ - PlatformFile(name: 'games.pgn', size: pgnBytes.length, bytes: pgnBytes), + _FakePlatformFile(name: 'games.pgn', size: pgnBytes.length, fileBytes: pgnBytes), ]), ); await tester.pumpWidget(app);