-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[file_selector] Fix default accept types on iOS (#4691)
Uses `public.data` as the default accept type on iOS, instead of an empty list, since unlike on macOS an empty list of accept types doesn't mean to accept every type, so the default on iOS was not allowing any files. Adds another page to the implementation package's example app to facilitate manual testing of this behavior for package developers. Fixes flutter/flutter#132211
- Loading branch information
1 parent
08080ab
commit 84218b9
Showing
7 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/file_selector/file_selector_ios/example/lib/open_any_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Screen that allows the user to select any file file using `openFile`, then | ||
/// displays its path in a dialog. | ||
class OpenAnyPage extends StatelessWidget { | ||
/// Default Constructor | ||
const OpenAnyPage({super.key}); | ||
|
||
Future<void> _openTextFile(BuildContext context) async { | ||
final XFile? file = await FileSelectorPlatform.instance.openFile(); | ||
if (file == null) { | ||
// Operation was canceled by the user. | ||
return; | ||
} | ||
|
||
if (context.mounted) { | ||
await showDialog<void>( | ||
context: context, | ||
builder: (BuildContext context) => PathDisplay(file.name, file.path), | ||
); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Open a file'), | ||
), | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
backgroundColor: Colors.blue, | ||
foregroundColor: Colors.white, | ||
), | ||
child: const Text('Press to open a file of any type'), | ||
onPressed: () => _openTextFile(context), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
/// Widget that displays a text file in a dialog. | ||
class PathDisplay extends StatelessWidget { | ||
/// Default Constructor. | ||
const PathDisplay(this.fileName, this.filePath, {super.key}); | ||
|
||
/// The name of the selected file. | ||
final String fileName; | ||
|
||
/// The contents of the text file. | ||
final String filePath; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: Text(fileName), | ||
content: Text(filePath), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: const Text('Close'), | ||
onPressed: () => Navigator.pop(context), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters