Skip to content

[cross_file] Updates cross_file to a package separated federated plugin #11010

Open
bparrishMines wants to merge 196 commits intoflutter:mainfrom
bparrishMines:new_crossfile
Open

[cross_file] Updates cross_file to a package separated federated plugin #11010
bparrishMines wants to merge 196 commits intoflutter:mainfrom
bparrishMines:new_crossfile

Conversation

@bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Feb 12, 2026

Updates cross_file to a package separated federated plugin. Keeping the package separation is still debatable.

Follows the general design outlined at https://flutter.dev/go/flutter-file-system

Implementation is split into

Pubspec dependencies have been changed to use ones from git to have runnable example apps while in development and review. Specifically because file_selector uses the current version of cross_file and I didn't want to make this a file_selector + cross_file PR. Can update it to this if preferred.

The reason file_selector is different for the example apps is because I wanted to ensue Android, iOS, macOS still work without copying the file to a file with the Apps sandbox.

Example

dependencies:
  cross_file:
    git:
      url: https://github.com/bparrishMines/packages
      ref: new_crossfile
      path: packages/cross_file/cross_file
  file_selector:
    git:
      url: https://github.com/bparrishMines/packages
      ref: new_file_selector
      path: packages/file_selector/file_selector

The cross_file example will run for all platforms except for linux and windows since they are simply using the dart:io implementation.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@bparrishMines bparrishMines changed the title New crossfile [cross_file] Updates cross_file to a package separated federated plugin Feb 12, 2026
@bparrishMines bparrishMines marked this pull request as ready for review February 13, 2026 16:19
@bparrishMines
Copy link
Contributor Author

@stuartmorgan-g This is ready for initial review. The tests are mostly failing on missing integration tests, missing examples in cross_file_io, and the git deps. I can work on fixing these while the code is being reviewed.

@bparrishMines bparrishMines requested a review from ditman February 13, 2026 16:21
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant and well-executed refactoring of cross_file into a federated plugin structure. The new architecture is clean and aligns with modern Flutter plugin conventions. I've identified a few areas for improvement related to dependency version consistency, native code safety, and asynchronous programming best practices, but overall this is a solid contribution.

Comment on lines +17 to +41
func tryCreateBookmarkedUrl(url: String) throws -> String? {
let nativeUrl = URL(string: url)!
let data = try nativeUrl.bookmarkData(
options: [],
includingResourceValuesForKeys: nil,
relativeTo: nil
)

var isStale: Bool = true
let bookmarkedUrl: URL = try URL(resolvingBookmarkData: data, bookmarkDataIsStale: &isStale)

if !isStale {
return bookmarkedUrl.absoluteString
}

return nil
}

func startAccessingSecurityScopedResource(url: String) throws -> Bool {
return URL(string: url)!.startAccessingSecurityScopedResource()
}

func stopAccessingSecurityScopedResource(url: String) throws {
URL(string: url)!.stopAccessingSecurityScopedResource()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of force unwrapping (!) when creating a URL from a string is unsafe and can lead to a runtime crash if the url string is malformed. It's better to handle this potential failure gracefully, for example by using guard let and throwing an error.

  func tryCreateBookmarkedUrl(url: String) throws -> String? {
    guard let nativeUrl = URL(string: url) else {
      throw PigeonError(code: "invalid_url", message: "Invalid URL string: \(url)", details: nil)
    }
    let data = try nativeUrl.bookmarkData(
      options: [],
      includingResourceValuesForKeys: nil,
      relativeTo: nil
    )

    var isStale: Bool = true
    let bookmarkedUrl: URL = try URL(resolvingBookmarkData: data, bookmarkDataIsStale: &isStale)

    if !isStale {
      return bookmarkedUrl.absoluteString
    }

    return nil
  }

  func startAccessingSecurityScopedResource(url: String) throws -> Bool {
    guard let nativeUrl = URL(string: url) else {
      throw PigeonError(code: "invalid_url", message: "Invalid URL string: \(url)", details: nil)
    }
    return nativeUrl.startAccessingSecurityScopedResource()
  }

  func stopAccessingSecurityScopedResource(url: String) throws {
    guard let nativeUrl = URL(string: url) else {
      throw PigeonError(code: "invalid_url", message: "Invalid URL string: \(url)", details: nil)
    }
    nativeUrl.stopAccessingSecurityScopedResource()
  }

IOXDirectoryExtension? get extension => this;

@override
Future<bool> exists() async => directory.existsSync();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using the synchronous existsSync() in an async method can block the event loop, potentially leading to UI unresponsiveness. It's recommended to use the asynchronous exists() method instead.

Suggested change
Future<bool> exists() async => directory.existsSync();
Future<bool> exists() => directory.exists();

Comment on lines +51 to +57
Future<DateTime?> lastModified() async {
try {
return file.lastModifiedSync();
} on FileSystemException {
return null;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using the synchronous lastModifiedSync() in an async method can block the event loop. Please use the asynchronous lastModified() method to avoid potential UI jank.

Suggested change
Future<DateTime?> lastModified() async {
try {
return file.lastModifiedSync();
} on FileSystemException {
return null;
}
}
Future<DateTime?> lastModified() async {
try {
return await file.lastModified();
} on FileSystemException {
return null;
}
}

Future<bool> canRead() => exists();

@override
Future<bool> exists() async => file.existsSync();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using the synchronous existsSync() in an async method can block the event loop. Please use the asynchronous exists() method to avoid potential UI jank.

Suggested change
Future<bool> exists() async => file.existsSync();
Future<bool> exists() => file.exists();

Comment on lines +5 to +13
ext.kotlin_version = "2.2.21"
repositories {
google()
mavenCentral()
}

dependencies {
classpath("com.android.tools.build:gradle:8.13.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are inconsistent versions of Gradle, the Android Gradle Plugin (AGP), and Kotlin across the new packages and examples. For instance, this file uses AGP 8.13.1 and Kotlin 2.2.21, while other parts of the PR use older versions (e.g., AGP 8.9.1, Kotlin 2.1.0). To improve maintainability and prevent potential build issues, it would be beneficial to align these versions to a consistent, recent set across all the new Android projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant