open_save_file_dialogs 0.1.3 copy "open_save_file_dialogs: ^0.1.3" to clipboard
open_save_file_dialogs: ^0.1.3 copied to clipboard

PlatformAndroid

A Flutter plugin for opening and saving files on Android, using the native file chooser.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:open_save_file_dialogs/open_save_file_dialogs.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _openSaveFileDialogsPlugin = OpenSaveFileDialogs();

  String? savedFileName;
  String? openedFileContent;

  void _selectSavedFile() async {
    try {
      final newFileName = await _openSaveFileDialogsPlugin.saveFileDialog(
          content: "This is a\nsimple test.\n", startingFileName: "test.txt");
      setState(() {
        savedFileName = newFileName;
      });
    } on Exception catch (e) {
      debugPrint("Error happened while trying to save : $e");
    }
  }

  void _selectOpenedFile() async {
    try {
      final content = await _openSaveFileDialogsPlugin.openFileDialog();
      setState(() {
        openedFileContent = content;
      });
    } on Exception catch (e) {
      debugPrint("Error happened while trying to open : $e");
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('OpenSaveFileDialogs example app'),
        ),
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text('Saved file name: $savedFileName'),
                ElevatedButton(
                  onPressed: _selectSavedFile,
                  child: const Text(
                    'Select saved file',
                  ),
                ),
                const SizedBox(height: 20),
                Expanded(
                  child: SingleChildScrollView(
                      child:
                          Text('Opened file content:\n\n$openedFileContent')),
                ),
                ElevatedButton(
                  onPressed: _selectOpenedFile,
                  child: const Text(
                    'Select opened file',
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}