mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Files selector: Allow choosing a directory
This commit is contained in:
parent
711b19c998
commit
d53b3bfce9
1 changed files with 26 additions and 9 deletions
|
|
@ -18,7 +18,20 @@ class FilesSelectorResult {
|
||||||
FilesSelectorResult(this.parentId, this.selection);
|
FilesSelectorResult(this.parentId, this.selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A screen for selecting files.
|
||||||
|
///
|
||||||
|
/// This returns a [FilesSelectorResult] when pooping the navigator. If
|
||||||
|
/// [chooseDirectory] is true, the user will select a directory instead. In
|
||||||
|
/// that case, the document ID of the directory will be returned directly.
|
||||||
|
/// If that value is null, this means that the toplevel directory was selected.
|
||||||
class FilesSelector extends StatefulWidget {
|
class FilesSelector extends StatefulWidget {
|
||||||
|
/// Choose a directory instead of multiple files.
|
||||||
|
final bool chooseDirectory;
|
||||||
|
|
||||||
|
FilesSelector({
|
||||||
|
this.chooseDirectory = false,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_FilesSelectorState createState() => _FilesSelectorState();
|
_FilesSelectorState createState() => _FilesSelectorState();
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +55,8 @@ class _FilesSelectorState extends State<FilesSelector> {
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Choose files'),
|
title: Text(
|
||||||
|
widget.chooseDirectory ? 'Choose directory' : 'Choose files'),
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|
@ -51,14 +65,15 @@ class _FilesSelectorState extends State<FilesSelector> {
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
FlatButton(
|
FlatButton(
|
||||||
child: Text('DONE'),
|
child: Text(widget.chooseDirectory ? 'SELECT' : 'DONE'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
final parentId = history.isNotEmpty ? history.last.id : null;
|
||||||
|
|
||||||
Navigator.pop(
|
Navigator.pop(
|
||||||
context,
|
context,
|
||||||
FilesSelectorResult(
|
widget.chooseDirectory
|
||||||
history.isNotEmpty ? history.last.id : null,
|
? parentId
|
||||||
selection,
|
: FilesSelectorResult(parentId, selection),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -141,9 +156,11 @@ class _FilesSelectorState extends State<FilesSelector> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setState(() {
|
if (mounted) {
|
||||||
children = newChildren;
|
setState(() {
|
||||||
});
|
children = newChildren;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool up() {
|
bool up() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue