Skip to content

Commit 17c1021

Browse files
authored
[file_selector] Avoids using path_provider in web example app. (#4445)
This is a minor change to the `file_selector` example app to prevent it from using `path_provider` when running on the web (because `path_provider` isn't available on the web). Fixes flutter/flutter#130368 (PS: This should be exempt from publishing requirements, because the modified file is not shown in pub.dev, or anywhere else AFAIK.)
1 parent aaebc6e commit 17c1021

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

-

Whitespace-only changes.

packages/file_selector/file_selector/example/lib/save_text_page.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:file_selector/file_selector.dart';
66
import 'package:flutter/foundation.dart';
77
import 'package:flutter/material.dart';
8-
import 'package:path_provider/path_provider.dart';
8+
import 'package:path_provider/path_provider.dart' as path_provider;
99

1010
/// Page for showing an example of saving with file_selector
1111
class SaveTextPage extends StatelessWidget {
@@ -21,9 +21,11 @@ class SaveTextPage extends StatelessWidget {
2121
final String fileName = _nameController.text;
2222
// This demonstrates using an initial directory for the prompt, which should
2323
// only be done in cases where the application can likely predict where the
24-
// file will be saved. In most cases, this parameter should not be provided.
25-
final String initialDirectory =
26-
(await getApplicationDocumentsDirectory()).path;
24+
// file will be saved. In most cases, this parameter should not be provided,
25+
// and in the web, path_provider shouldn't even be called.
26+
final String? initialDirectory = kIsWeb
27+
? null
28+
: (await path_provider.getApplicationDocumentsDirectory()).path;
2729
final FileSaveLocation? result = await getSaveLocation(
2830
initialDirectory: initialDirectory,
2931
suggestedName: fileName,

0 commit comments

Comments
 (0)