easy_folder_picker 1.2.0 easy_folder_picker: ^1.2.0 copied to clipboard
Easy directory picker for Flutter, you can choose directory or create directory for further action
import 'dart:io';
import 'package:easy_folder_picker/FolderPicker.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Easy Folder Picker',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
Directory? selectedDirectory;
Future<void> _pickDirectory(BuildContext context) async {
Directory? directory = selectedDirectory;
if (directory == null) {
directory = Directory(FolderPicker.ROOTPATH);
}
Directory? newDirectory = await FolderPicker.pick(
allowFolderCreation: true,
context: context,
rootDirectory: directory,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))));
setState(() {
selectedDirectory = newDirectory;
print(selectedDirectory);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Folder"),
centerTitle: true,
),
body: Container(
child: Column(
children: [
IconButton(
icon: Icon(Icons.file_download),
onPressed: () {
_pickDirectory(context);
},
),
selectedDirectory != null
? Text("Selected Path : ${selectedDirectory!.path}")
: Container(),
],
),
),
);
}
}