Skip to content

Commit 41d5ca9

Browse files
[file_selector] Endorse Android (flutter#4329)
Endorses the new Android implementation of `file_selector`, updating the README accordingly. Also adjusts the example to better handle platform diffs, by hiding UI that doesn't work instead of just labelling it on the button. Left a TODO to improve how we determine what to hide once we have the API to do so. Fixes flutter#110098
1 parent 6ab9a8b commit 41d5ca9

File tree

29 files changed

+325
-40
lines changed

29 files changed

+325
-40
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ updates:
159159
- dependency-name: "*"
160160
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
161161

162+
- package-ecosystem: "gradle"
163+
directory: "/packages/file_selector/file_selector/example/android/app"
164+
commit-message:
165+
prefix: "[file_selector]"
166+
schedule:
167+
interval: "weekly"
168+
open-pull-requests-limit: 10
169+
ignore:
170+
- dependency-name: "*"
171+
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
172+
162173
- package-ecosystem: "gradle"
163174
directory: "/packages/file_selector/file_selector_android/android"
164175
commit-message:

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ packages/**/*_web/** @ditman
5353
packages/camera/camera_android/** @camsim99
5454
packages/camera/camera_android_camerax/** @camsim99
5555
packages/espresso/** @reidbaker
56+
packages/file_selector/file_selector_android/** @gmackall
5657
packages/flutter_plugin_android_lifecycle/** @reidbaker
5758
packages/google_maps_flutter/google_maps_flutter_android/** @reidbaker
5859
packages/google_sign_in/google_sign_in_android/** @camsim99

packages/file_selector/file_selector/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.5
2+
3+
* Adds an endorsed Android implementation.
4+
15
## 0.9.4
26

37
* Adds `getSaveLocation` and deprecates `getSavePath`.

packages/file_selector/file_selector/README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
A Flutter plugin that manages files and interactions with file dialogs.
88

9-
| | iOS | Linux | macOS | Web | Windows |
10-
|-------------|---------|-------|--------|-----|-------------|
11-
| **Support** | iOS 11+ | Any | 10.14+ | Any | Windows 10+ |
9+
| | Android | iOS | Linux | macOS | Web | Windows |
10+
|-------------|---------|---------|-------|--------|-----|-------------|
11+
| **Support** | SDK 19+ | iOS 11+ | Any | 10.14+ | Any | Windows 10+ |
1212

1313
## Usage
1414

@@ -100,23 +100,25 @@ Different platforms support different type group filter options. To avoid
100100
filters that cover all platforms you are targeting, or that you conditionally
101101
pass different `XTypeGroup`s based on `Platform`.
102102

103-
| | iOS | Linux | macOS | Web | Windows |
104-
|--------------------------|-----|-------|--------|-----|-------------|
105-
| `extensions` | | ✔️ | ✔️ | ✔️ | ✔️ |
106-
| `mimeTypes` | | ✔️ | ✔️† | ✔️ | |
107-
| `uniformTypeIdentifiers` | ✔️ | | ✔️ | | |
108-
| `webWildCards` | | | | ✔️ | |
103+
| | Andoid | iOS | Linux | macOS | Web | Windows |
104+
|--------------------------|--------|-----|-------|--------|-----|-------------|
105+
| `extensions` | ✔️ | | ✔️ | ✔️ | ✔️ | ✔️ |
106+
| `mimeTypes` | ✔️ | | ✔️ | ✔️† | ✔️ | |
107+
| `uniformTypeIdentifiers` | | ✔️ | | ✔️ | | |
108+
| `webWildCards` | | | | | ✔️ | |
109109

110110
`mimeTypes` are not supported on version of macOS earlier than 11 (Big Sur).
111111

112112
### Features supported by platform
113113

114-
| Feature | Description | iOS | Linux | macOS | Windows | Web |
115-
| ---------------------- |----------------------------------- |--------- | ---------- | -------- | ------------ | ----------- |
116-
| Choose a single file | Pick a file/image | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
117-
| Choose multiple files | Pick multiple files/images | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
118-
| Choose a save location | Pick a directory to save a file in || ✔️ | ✔️ | ✔️ ||
119-
| Choose a directory | Pick a folder and get its path || ✔️ | ✔️ | ✔️ ||
114+
| Feature | Description | Android | iOS | Linux | macOS | Windows | Web |
115+
| ---------------------- |----------------------------------- |---------|--------- | ---------- | -------- | ------------ | ----------- |
116+
| Choose a single file | Pick a file/image | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
117+
| Choose multiple files | Pick multiple files/images | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
118+
| Choose a save location | Pick a directory to save a file in ||| ✔️ | ✔️ | ✔️ ||
119+
| Choose a directory | Pick a directory and get its path | ✔️† || ✔️ | ✔️ | ✔️ ||
120+
121+
† Choosing a directory is no supported on versions of Android before SDK 21 (Lollipop).
120122

121123
[example]:./example
122124
[entitlement]: https://docs.flutter.dev/desktop#entitlements-and-the-app-sandbox
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withReader('UTF-8') { reader ->
5+
localProperties.load(reader)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15+
if (flutterVersionCode == null) {
16+
flutterVersionCode = '1'
17+
}
18+
19+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20+
if (flutterVersionName == null) {
21+
flutterVersionName = '1.0'
22+
}
23+
24+
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
26+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
28+
android {
29+
namespace "dev.flutter.plugins.file_selector_example"
30+
compileSdkVersion flutter.compileSdkVersion
31+
ndkVersion flutter.ndkVersion
32+
33+
compileOptions {
34+
sourceCompatibility JavaVersion.VERSION_1_8
35+
targetCompatibility JavaVersion.VERSION_1_8
36+
}
37+
38+
kotlinOptions {
39+
jvmTarget = '1.8'
40+
}
41+
42+
sourceSets {
43+
main.java.srcDirs += 'src/main/kotlin'
44+
}
45+
46+
defaultConfig {
47+
applicationId "dev.flutter.plugins.file_selector_example"
48+
// You can update the following values to match your application needs.
49+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
50+
minSdkVersion 19
51+
targetSdkVersion flutter.targetSdkVersion
52+
versionCode flutterVersionCode.toInteger()
53+
versionName flutterVersionName
54+
}
55+
56+
buildTypes {
57+
release {
58+
// TODO: Add your own signing config for the release build.
59+
// Signing with the debug keys for now, so `flutter run --release` works.
60+
signingConfig signingConfigs.debug
61+
}
62+
}
63+
}
64+
65+
flutter {
66+
source '../..'
67+
}
68+
69+
dependencies {
70+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
71+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application
3+
android:label="file_selector_example"
4+
android:name="${applicationName}"
5+
android:icon="@mipmap/ic_launcher">
6+
<activity
7+
android:name=".MainActivity"
8+
android:exported="true"
9+
android:launchMode="singleTop"
10+
android:theme="@style/LaunchTheme"
11+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
12+
android:hardwareAccelerated="true"
13+
android:windowSoftInputMode="adjustResize">
14+
<!-- Specifies an Android theme to apply to this Activity as soon as
15+
the Android process has started. This theme is visible to the user
16+
while the Flutter UI initializes. After that, this theme continues
17+
to determine the Window background behind the Flutter UI. -->
18+
<meta-data
19+
android:name="io.flutter.embedding.android.NormalTheme"
20+
android:resource="@style/NormalTheme"
21+
/>
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN"/>
24+
<category android:name="android.intent.category.LAUNCHER"/>
25+
</intent-filter>
26+
</activity>
27+
<!-- Don't delete the meta-data below.
28+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
29+
<meta-data
30+
android:name="flutterEmbedding"
31+
android:value="2" />
32+
</application>
33+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.plugins.file_selector_example
6+
7+
import io.flutter.embedding.android.FlutterActivity
8+
9+
class MainActivity: FlutterActivity() {
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="@android:color/white" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
the Flutter engine draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
the Flutter engine draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
buildscript {
2+
ext.kotlin_version = '1.7.10'
3+
repositories {
4+
google()
5+
mavenCentral()
6+
}
7+
8+
dependencies {
9+
classpath 'com.android.tools.build:gradle:7.3.0'
10+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
google()
17+
mavenCentral()
18+
}
19+
}
20+
21+
rootProject.buildDir = '../build'
22+
subprojects {
23+
project.buildDir = "${rootProject.buildDir}/${project.name}"
24+
}
25+
subprojects {
26+
project.evaluationDependsOn(':app')
27+
}
28+
29+
tasks.register("clean", Delete) {
30+
delete rootProject.buildDir
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.gradle.jvmargs=-Xmx1536M
2+
android.useAndroidX=true
3+
android.enableJetifier=true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
zipStoreBase=GRADLE_USER_HOME
4+
zipStorePath=wrapper/dists
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include ':app'
2+
3+
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4+
def properties = new Properties()
5+
6+
assert localPropertiesFile.exists()
7+
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8+
9+
def flutterSdkPath = properties.getProperty("flutter.sdk")
10+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11+
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

packages/file_selector/file_selector/example/lib/get_directory_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class GetDirectoryPage extends StatelessWidget {
5050
),
5151
onPressed: _isIOS ? null : () => _getDirectoryPath(context),
5252
child: const Text(
53-
'Press to ask user to choose a directory (not supported on iOS).',
53+
'Press to ask user to choose a directory.',
5454
),
5555
),
5656
],

0 commit comments

Comments
 (0)