mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Tracks editor: Make tracks reorderable
This commit is contained in:
parent
20d685a3eb
commit
090c4501b1
1 changed files with 53 additions and 42 deletions
|
|
@ -37,54 +37,65 @@ class _TracksEditorState extends State<TracksEditor> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ReorderableListView(
|
||||||
children: <Widget>[
|
header: Column(
|
||||||
recordingId != null
|
children: <Widget>[
|
||||||
? RecordingTile(
|
recordingId != null
|
||||||
recordingId: recordingId,
|
? RecordingTile(
|
||||||
onTap: selectRecording,
|
recordingId: recordingId,
|
||||||
)
|
onTap: selectRecording,
|
||||||
: ListTile(
|
)
|
||||||
title: Text('Select recording'),
|
: ListTile(
|
||||||
onTap: selectRecording,
|
title: Text('Select recording'),
|
||||||
),
|
onTap: selectRecording,
|
||||||
ListTile(
|
|
||||||
title: Text('Files'),
|
|
||||||
trailing: IconButton(
|
|
||||||
icon: const Icon(Icons.add),
|
|
||||||
onPressed: () async {
|
|
||||||
final Set<String> paths = await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => FilesSelector(
|
|
||||||
baseDirectory: backend.musicLibraryPath,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
|
||||||
|
|
||||||
if (paths != null) {
|
|
||||||
setState(() {
|
|
||||||
for (final path in paths) {
|
|
||||||
tracks.add(TrackModel(path));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
for (final track in tracks)
|
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(track.path),
|
title: Text('Files'),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: const Icon(Icons.delete),
|
icon: const Icon(Icons.add),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
setState(() {
|
final Set<String> paths = await Navigator.push(
|
||||||
tracks.remove(track);
|
context,
|
||||||
});
|
MaterialPageRoute(
|
||||||
|
builder: (context) => FilesSelector(
|
||||||
|
baseDirectory: backend.musicLibraryPath,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (paths != null) {
|
||||||
|
setState(() {
|
||||||
|
for (final path in paths) {
|
||||||
|
tracks.add(TrackModel(path));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
children: tracks
|
||||||
|
.map((t) => ListTile(
|
||||||
|
key: Key(t.hashCode.toString()),
|
||||||
|
title: Text(t.path),
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
tracks.remove(t);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
onReorder: (i1, i2) {
|
||||||
|
setState(() {
|
||||||
|
final track = tracks.removeAt(i1);
|
||||||
|
final newIndex = i2 > i1 ? i2 - 1 : i2;
|
||||||
|
tracks.insert(newIndex, track);
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue