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

outdated

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 {
    final newFileName = await _openSaveFileDialogsPlugin.saveFileDialog(
        content: "This is a\nsimple test.\n", startingFileName: "test.txt");
    setState(() {
      savedFileName = newFileName;
    });
  }

  void _selectOpenedFile() async {
    final content = await _openSaveFileDialogsPlugin.openFileDialog();
    setState(() {
      openedFileContent = content;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('OpenSaveFileDialogs example app'),
        ),
        body: 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),
              Text('Opened file content: $openedFileContent'),
              ElevatedButton(
                onPressed: _selectOpenedFile,
                child: const Text(
                  'Select opened file',
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}