Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
tugorez committed Jan 22, 2021
1 parent faa26ec commit 6ef2634
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OpenTextPage extends StatelessWidget {
label: 'text',
extensions: ['txt', 'json'],
);
final XFile file = await openFile(acceptedTypeGroups: [typeGroup]);
final XFile file = await openFile();
final String fileName = file.name;
final String fileContent = await file.readAsString();

Expand Down
21 changes: 19 additions & 2 deletions packages/file_selector/file_selector/lib/file_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
// found in the LICENSE file.

import 'dart:async';

import 'package:logger/logger.dart';
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';

export 'package:file_selector_platform_interface/file_selector_platform_interface.dart'
show XFile, XTypeGroup;

final _logger = Logger();

/// Open file dialog for loading files and return a file path
Future<XFile> openFile({
List<XTypeGroup> acceptedTypeGroups,
String initialDirectory,
String confirmButtonText,
}) {
_verifyExtensions(acceptedTypeGroups);
return FileSelectorPlatform.instance.openFile(
acceptedTypeGroups: acceptedTypeGroups,
initialDirectory: initialDirectory,
Expand All @@ -27,6 +29,7 @@ Future<List<XFile>> openFiles({
String initialDirectory,
String confirmButtonText,
}) {
_verifyExtensions(acceptedTypeGroups);
return FileSelectorPlatform.instance.openFiles(
acceptedTypeGroups: acceptedTypeGroups,
initialDirectory: initialDirectory,
Expand All @@ -40,6 +43,7 @@ Future<String> getSavePath({
String suggestedName,
String confirmButtonText,
}) async {
_verifyExtensions(acceptedTypeGroups);
return FileSelectorPlatform.instance.getSavePath(
acceptedTypeGroups: acceptedTypeGroups,
initialDirectory: initialDirectory,
Expand All @@ -55,3 +59,16 @@ Future<String> getDirectoryPath({
return FileSelectorPlatform.instance.getDirectoryPath(
initialDirectory: initialDirectory, confirmButtonText: confirmButtonText);
}

void _verifyExtensions(List<XTypeGroup> acceptedTypeGroups) {
acceptedTypeGroups?.asMap()?.forEach((i, acceptedTypeGroup) {
acceptedTypeGroup.extensions?.asMap()?.forEach((j, ext) {
if (ext.startsWith('.')) {
_logger.w(
'acceptedTypeGroups[${i}].extensions[${j}] with value "${ext}" is invalid.'
' Remove the leading dot.',
);
}
});
});
}
1 change: 1 addition & 0 deletions packages/file_selector/file_selector/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
flutter:
sdk: flutter
file_selector_platform_interface: ^1.0.0
logger: ^0.9.4

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 6ef2634

Please sign in to comment.