Skip to content

[file_selector] Add Android implementation for getSavePath #113441

Open

Description

@gantelo

Use case

Calling getSavePath in Android should return a storage path for the user to save a file of any type in there.

The following is an example of use, without managing permissions or exceptions, to show how a really happy path would look.

// other imports 
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';

class X {

  // other functions

  Future<void> _saveFile() async {
    final String? savePath = await FileSelectorPlatform.instance.getSavePath(
      suggestedName: 'somefile.txt',
    );

    final String text = 'Example text';
    final Uint8List fileData = Uint8List.fromList(text.codeUnits);

    const String fileMimeType = 'text/plain';

    final XFile textFile =
        XFile.fromData(fileData, mimeType: fileMimeType, name: fileName);

    await textFile.saveTo(path);
  }
}

Proposal

As discussed in the PR #6547, we're leaving behind the Android implementation for getSavePath due to the fundamental working differences with the other platforms.

The proposal is to add the implementation for getSavePath to the Android platform and discuss the best approach.

You can follow the discussion that triggered this issue here.

And we have a draft PR with an implementation here.

This should be implemented after the Android implementation for file_selector is 'live'.

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    platform-androidAndroid applications specifically
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Oct 17, 2022
  2. yegor-pelykh commented on Apr 11, 2023

    @yegor-pelykh
  3. added
    P3Issues that are less important to the Flutter project
    and removed on Jun 28, 2023
  4. epw commented on Dec 10, 2024

    @epw

    This would be helpful for me. I am writing an app which serializes its state to a file that the user should be free to interact with through their filesystem (for example, picking a file in a Dropbox folder, so it will be automatically copied to other devices with other platforms). As far as I can tell, getSaveLocation() would implement exactly the interface I want to present to the user: an OS-native file picker that does not require excess permissions. Please consider adding Android support!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: file_selectorThe file_selector pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions