Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
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
6 changes: 4 additions & 2 deletions packages/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Future<Directory> getTemporaryDirectory() async {
///
/// On Android, this function throws an [UnsupportedError].
Future<Directory> getApplicationSupportDirectory() async {
if (!Platform.isIOS)
throw UnsupportedError("getApplicationSupportDirectory requires iOS");
if (!(Platform.isIOS || Platform.isMacOS))
throw UnsupportedError("getApplicationSupportDirectory requires iOS or macOS");
final String path =
await _channel.invokeMethod<String>('getApplicationSupportDirectory');
if (path == null) {
Expand Down Expand Up @@ -80,6 +80,8 @@ Future<Directory> getApplicationDocumentsDirectory() async {
Future<Directory> getExternalStorageDirectory() async {
if (Platform.isIOS)
throw UnsupportedError("Functionality not available on iOS");
if (Platform.isMacOS)
throw UnsupportedError("Functionality not implemented on macOS");
final String path =
await _channel.invokeMethod<String>('getStorageDirectory');
if (path == null) {
Expand Down
51 changes: 51 additions & 0 deletions packages/path_provider/macos/Classes/PathProviderPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2019 The Chromium 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 FlutterMacOS
import Foundation

public class PathProviderPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(
name: "plugins.flutter.io/path_provider",
binaryMessenger: registrar.messenger)
let instance = PathProviderPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let method = call.method
if method == "getTemporaryDirectory" {
result(getDirectory(ofType: FileManager.SearchPathDirectory.cachesDirectory))
} else if method == "getApplicationDocumentsDirectory" {
result(getDirectory(ofType: FileManager.SearchPathDirectory.documentDirectory))
} else if (method == "getApplicationSupportDirectory") {
var path = getDirectory(ofType: FileManager.SearchPathDirectory.applicationSupportDirectory)
if let basePath = path {
let basePathURL = URL.init(fileURLWithPath: basePath)
path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path
do {
try FileManager.default.createDirectory(atPath: path!, withIntermediateDirectories: true)
} catch {
result(FlutterError(
code:"directory_creation_failure",
message: error.localizedDescription,
details: "\(error)"))
return
}
}
result(path)
} else {
result(FlutterMethodNotImplemented)
}
}
}

private func getDirectory(ofType directory: FileManager.SearchPathDirectory) -> String? {
let paths = NSSearchPathForDirectoriesInDomains(
directory,
FileManager.SearchPathDomainMask.userDomainMask,
true)
return paths.first
}
21 changes: 21 additions & 0 deletions packages/path_provider/macos/path_provider.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'path_provider'
s.version = '0.0.1'
s.summary = 'A Flutter plugin for getting commonly used locations on the filesystem.'
s.description = <<-DESC
A Flutter plugin for getting commonly used locations on the filesystem.
DESC
s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/path_provider'
s.license = { :file => '../LICENSE' }
s.author = { 'Flutter Team' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'FlutterMacOS'

s.platform = :osx
s.osx.deployment_target = '10.12'
end

1 change: 1 addition & 0 deletions packages/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ flutter:
plugin:
androidPackage: io.flutter.plugins.pathprovider
iosPrefix: FLT
macosPrefix: FLT
pluginClass: PathProviderPlugin

dependencies:
Expand Down