Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.4.5

* Add support for v2 plugins APIs.

## 1.4.4

* Update driver tests in the example app to e2e tests.
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ afterEvaluate {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

package io.flutter.plugins.pathprovider;

import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
Expand All @@ -17,19 +19,33 @@
import java.util.ArrayList;
import java.util.List;

public class PathProviderPlugin implements MethodCallHandler {
public class PathProviderPlugin implements FlutterPlugin, MethodCallHandler {

private final Registrar mRegistrar;
private Context context;
private MethodChannel channel;

public PathProviderPlugin() {}

public static void registerWith(Registrar registrar) {
MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider");
PathProviderPlugin instance = new PathProviderPlugin(registrar);
channel.setMethodCallHandler(instance);
PathProviderPlugin instance = new PathProviderPlugin();
instance.channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider");
instance.context = registrar.context();
instance.channel.setMethodCallHandler(instance);
}

private PathProviderPlugin(Registrar registrar) {
this.mRegistrar = registrar;
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
channel =
new MethodChannel(
binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/path_provider");
context = binding.getApplicationContext();
channel.setMethodCallHandler(this);
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
channel = null;
}

@Override
Expand Down Expand Up @@ -61,19 +77,19 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
}

private String getPathProviderTemporaryDirectory() {
return mRegistrar.context().getCacheDir().getPath();
return context.getCacheDir().getPath();
}

private String getApplicationSupportDirectory() {
return PathUtils.getFilesDir(mRegistrar.context());
return PathUtils.getFilesDir(context);
}

private String getPathProviderApplicationDocumentsDirectory() {
return PathUtils.getDataDirectory(mRegistrar.context());
return PathUtils.getDataDirectory(context);
}

private String getPathProviderStorageDirectory() {
final File dir = mRegistrar.context().getExternalFilesDir(null);
final File dir = context.getExternalFilesDir(null);
if (dir == null) {
return null;
}
Expand All @@ -84,13 +100,13 @@ private List<String> getPathProviderExternalCacheDirectories() {
final List<String> paths = new ArrayList<>();

if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
for (File dir : mRegistrar.context().getExternalCacheDirs()) {
for (File dir : context.getExternalCacheDirs()) {
if (dir != null) {
paths.add(dir.getAbsolutePath());
}
}
} else {
File dir = mRegistrar.context().getExternalCacheDir();
File dir = context.getExternalCacheDir();
if (dir != null) {
paths.add(dir.getAbsolutePath());
}
Expand All @@ -103,13 +119,13 @@ private List<String> getPathProviderExternalStorageDirectories(String type) {
final List<String> paths = new ArrayList<>();

if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
for (File dir : mRegistrar.context().getExternalFilesDirs(type)) {
for (File dir : context.getExternalFilesDirs(type)) {
if (dir != null) {
paths.add(dir.getAbsolutePath());
}
}
} else {
File dir = mRegistrar.context().getExternalFilesDir(type);
File dir = context.getExternalFilesDir(type);
if (dir != null) {
paths.add(dir.getAbsolutePath());
}
Expand Down
4 changes: 4 additions & 0 deletions packages/path_provider/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ flutter {
}

dependencies {
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

package io.flutter.plugins.pathprovider;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import io.flutter.plugins.pathproviderexample.EmbeddingV1Activity;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class EmbeddingV1ActivityTest {
@Rule
public ActivityTestRule<EmbeddingV1Activity> rule =
new ActivityTestRule<>(EmbeddingV1Activity.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

package io.flutter.plugins.pathprovider;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import io.flutter.plugins.pathproviderexample.MainActivity;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class MainActivityTest {
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application android:name="io.flutter.app.FlutterApplication" android:label="path_provider_example" android:icon="@mipmap/ic_launcher">
<activity
android:name=".EmbeddingV1Activity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

package io.flutter.plugins.pathproviderexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class EmbeddingV1Activity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

package io.flutter.plugins.pathproviderexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import dev.flutter.plugins.e2e.E2EPlugin;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.pathprovider.PathProviderPlugin;

public class MainActivity extends FlutterActivity {

// TODO(xster): Remove this once v2 of GeneratedPluginRegistrant rolls to stable. https://github.com/flutter/flutter/issues/42694
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new PathProviderPlugin());
flutterEngine.getPlugins().add(new E2EPlugin());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
2 changes: 1 addition & 1 deletion packages/path_provider/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ dependencies:
path: ../

dev_dependencies:
e2e: ^0.2.1
flutter_driver:
sdk: flutter
test: any
e2e: ^0.2.1

flutter:
uses-material-design: true
5 changes: 3 additions & 2 deletions packages/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for getting commonly used locations on the Android &
iOS file systems, such as the temp and app data directories.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider
version: 1.4.4
version: 1.4.5

flutter:
plugin:
Expand All @@ -18,6 +18,7 @@ dependencies:
meta: ^1.0.5

dev_dependencies:
e2e: ^0.2.1
flutter_test:
sdk: flutter
flutter_driver:
Expand All @@ -27,4 +28,4 @@ dev_dependencies:

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=0.1.4 <2.0.0"
flutter: ">=1.9.1+hotfix.5 <2.0.0"
12 changes: 12 additions & 0 deletions packages/path_provider/test/path_provider_e2e.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider/path_provider.dart';
import 'package:e2e/e2e.dart';

void main() {
E2EWidgetsFlutterBinding.ensureInitialized();

testWidgets('Can get temporary directory', (WidgetTester tester) async {
final String tempPath = (await getTemporaryDirectory()).path;
expect(tempPath, isNotEmpty);
});
}