From 058e97a8f20b2335e72ceb07185160625523325b Mon Sep 17 00:00:00 2001 From: stonegate Date: Sun, 9 Aug 2020 01:25:52 +0800 Subject: [PATCH] Reorder bug fixed. --- lib/home/audioplayer.dart | 24 ++++++++++++++++++++++++ lib/home/playlist.dart | 28 +++++++++++++--------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/home/audioplayer.dart b/lib/home/audioplayer.dart index 775f4a5..287bd3d 100644 --- a/lib/home/audioplayer.dart +++ b/lib/home/audioplayer.dart @@ -288,6 +288,30 @@ class LastPosition extends StatelessWidget { textColor: data ? Colors.white : null, onPressed: () => audio.setSkipSilence(skipSilence: !data))), SizedBox(width: 10), + Selector( + selector: (_, audio) => audio.boostVolume, + builder: (_, data, __) => FlatButton( + child: Row( + children: [ + Icon(Icons.flash_on, size: 18), + SizedBox(width: 5), + Text('Boost Volume'), + ], + ), + color: data ? context.accentColor : Colors.transparent, + padding: EdgeInsets.symmetric(horizontal: 10), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(100.0), + side: BorderSide( + color: data + ? context.accentColor + : Theme.of(context) + .colorScheme + .onSurface + .withOpacity(0.12))), + textColor: data ? Colors.white : null, + onPressed: () => audio.setBoostVolume(boostVolume: !data))), + SizedBox(width: 10), FutureBuilder( future: getPosition(episode), builder: (context, snapshot) { diff --git a/lib/home/playlist.dart b/lib/home/playlist.dart index a80460a..a35faf8 100644 --- a/lib/home/playlist.dart +++ b/lib/home/playlist.dart @@ -41,6 +41,7 @@ class _PlaylistPageState extends State { } double _topHeight; + List episodes = []; @override void initState() { @@ -72,14 +73,14 @@ class _PlaylistPageState extends State { appBar: AppBar( title: _topHeight == 60 ? Text(s.homeMenuPlaylist) : Center(), elevation: 0, - backgroundColor: Theme.of(context).primaryColor, + backgroundColor: context.primaryColor, ), body: SafeArea( child: Selector>( selector: (_, audio) => Tuple3(audio.queue, audio.playerRunning, audio.queueUpdate), builder: (_, data, __) { - final episodes = data.item1.playlist; + episodes = data.item1.playlist; return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, @@ -103,10 +104,7 @@ class _PlaylistPageState extends State { ? '${s.homeMenuPlaylist}\n' : '', style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyText1 - .color, + color: context.textColor, fontSize: 30, ), children: [ @@ -124,7 +122,7 @@ class _PlaylistPageState extends State { ? 'episode' : 'episodes', style: TextStyle( - color: Theme.of(context).accentColor, + color: context.accentColor, fontSize: 15, )), TextSpan( @@ -132,14 +130,14 @@ class _PlaylistPageState extends State { _sumPlaylistLength(episodes).toString(), style: GoogleFonts.cairo( textStyle: TextStyle( - color: Theme.of(context).accentColor, + color: context.accentColor, fontSize: 25, )), ), TextSpan( text: 'mins', style: TextStyle( - color: Theme.of(context).accentColor, + color: context.accentColor, fontSize: 15, )), ], @@ -226,8 +224,7 @@ class _PlaylistPageState extends State { padding: EdgeInsets.all(0), alignment: Alignment.center, icon: Icon(Icons.play_circle_filled, - size: 40, - color: Theme.of(context).accentColor), + size: 40, color: (context).accentColor), onPressed: () { audio.playlistLoad(); // setState(() {}); @@ -247,10 +244,11 @@ class _PlaylistPageState extends State { if (newIndex > oldIndex) { newIndex -= 1; } - final episodeRemove = episodes[oldIndex]; - audio.delFromPlaylist(episodeRemove); - audio.addToPlaylistAt(episodeRemove, newIndex); - setState(() {}); + audio.reorderPlaylist(newIndex, oldIndex); + final episodeRemove = episodes.removeAt(oldIndex); + setState(() { + episodes.insert(newIndex, episodeRemove); + }); }, scrollDirection: Axis.vertical, children: data.item2