tsacdop-podcast-app-android/lib/widgets/dismissible_container.dart

226 lines
8.2 KiB
Dart
Raw Normal View History

2020-12-20 10:35:39 +01:00
import 'package:flutter/material.dart';
import 'package:line_icons/line_icons.dart';
import 'package:provider/provider.dart';
import '../state/audio_state.dart';
import '../type/episodebrief.dart';
import '../util/extension_helper.dart';
import 'custom_widget.dart';
class DismissibleContainer extends StatefulWidget {
2022-04-30 17:16:19 +02:00
final EpisodeBrief? episode;
final ValueChanged<bool>? onRemove;
DismissibleContainer({this.episode, this.onRemove, Key? key})
2020-12-20 10:35:39 +01:00
: super(key: key);
@override
_DismissibleContainerState createState() => _DismissibleContainerState();
}
class _DismissibleContainerState extends State<DismissibleContainer> {
2022-04-30 17:16:19 +02:00
late bool _delete;
2020-12-20 10:35:39 +01:00
@override
void initState() {
_delete = false;
super.initState();
}
@override
Widget build(BuildContext context) {
final s = context.s;
return AnimatedContainer(
duration: Duration(milliseconds: 300),
curve: Curves.easeInSine,
alignment: Alignment.center,
height: _delete ? 0 : 91.0,
2020-12-20 10:35:39 +01:00
child: _delete
? Container(
color: Colors.transparent,
)
: Column(
2021-02-17 16:25:23 +01:00
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Dismissible(
2022-04-30 17:16:19 +02:00
key: ValueKey('${widget.episode!.enclosureUrl}dis'),
background: Container(
padding: EdgeInsets.symmetric(horizontal: 20.0),
height: 30,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.red),
padding: EdgeInsets.all(5),
alignment: Alignment.center,
child: Icon(
2021-02-09 18:55:51 +01:00
LineIcons.alternateTrash,
color: Colors.white,
size: 15,
),
),
Container(
decoration: BoxDecoration(
shape: BoxShape.circle, color: Colors.red),
padding: EdgeInsets.all(5),
alignment: Alignment.center,
child: Icon(
2021-02-09 18:55:51 +01:00
LineIcons.alternateTrash,
color: Colors.white,
size: 15,
),
),
],
2020-12-20 10:35:39 +01:00
),
),
onDismissed: (direction) async {
setState(() {
_delete = true;
});
var index = await context
.read<AudioPlayerNotifier>()
2022-04-30 17:16:19 +02:00
.delFromPlaylist(widget.episode!);
widget.onRemove!(true);
final episodeRemove = widget.episode;
Scaffold.of(context).removeCurrentSnackBar();
Scaffold.of(context).showSnackBar(SnackBar(
behavior: SnackBarBehavior.floating,
backgroundColor: Colors.grey[800],
2022-06-03 16:29:19 +02:00
content: Text(s.toastRemovePlaylist,
style: TextStyle(color: Colors.white)),
action: SnackBarAction(
textColor: context.accentColor,
label: s.undo,
onPressed: () async {
await context
.read<AudioPlayerNotifier>()
2022-04-30 17:16:19 +02:00
.addToPlaylistAt(episodeRemove!, index);
widget.onRemove!(false);
}),
));
},
child: EpisodeCard(
2022-04-30 17:16:19 +02:00
widget.episode!,
isPlaying: false,
canReorder: true,
showDivider: false,
onTap: () async {
2020-12-20 10:35:39 +01:00
await context
.read<AudioPlayerNotifier>()
.episodeLoad(widget.episode);
2022-04-30 17:16:19 +02:00
widget.onRemove!(true);
},
),
),
),
Divider(height: 1)
2021-02-17 16:25:23 +01:00
],
),
2020-12-31 19:08:46 +01:00
);
}
}
class EpisodeCard extends StatelessWidget {
final EpisodeBrief episode;
2022-04-30 17:16:19 +02:00
final Color? tileColor;
final VoidCallback? onTap;
final bool? isPlaying;
2021-01-02 11:48:55 +01:00
final bool canReorder;
final bool showDivider;
2021-02-17 16:25:23 +01:00
final bool havePadding;
2020-12-31 19:08:46 +01:00
const EpisodeCard(this.episode,
2021-01-02 11:48:55 +01:00
{this.tileColor,
this.onTap,
this.isPlaying,
this.canReorder = false,
this.showDivider = true,
2021-02-17 16:25:23 +01:00
this.havePadding = false,
2022-04-30 17:16:19 +02:00
Key? key})
: assert(episode != null),
super(key: key);
2020-12-31 19:08:46 +01:00
@override
Widget build(BuildContext context) {
final s = context.s;
final c = episode.backgroudColor(context);
return SizedBox(
height: 90.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Expanded(
child: ListTile(
tileColor: tileColor,
contentPadding: EdgeInsets.symmetric(vertical: 8),
onTap: onTap,
title: Container(
child: Text(
2022-04-30 17:16:19 +02:00
episode.title!,
2021-01-24 17:16:59 +01:00
maxLines: 2,
2020-12-31 19:08:46 +01:00
overflow: TextOverflow.ellipsis,
),
),
leading: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
2021-02-17 16:25:23 +01:00
if (canReorder && !havePadding)
Icon(Icons.unfold_more, color: c),
SizedBox(width: canReorder && !havePadding ? 0 : 24),
2020-12-31 19:08:46 +01:00
CircleAvatar(
backgroundColor: c.withOpacity(0.5),
backgroundImage: episode.avatarImage),
],
),
subtitle: Container(
padding: EdgeInsets.only(top: 5, bottom: 5),
height: 35,
child: Row(
2020-12-20 10:35:39 +01:00
children: <Widget>[
2020-12-31 19:08:46 +01:00
if (episode.explicit == 1)
Container(
decoration: BoxDecoration(
color: Colors.red[800], shape: BoxShape.circle),
height: 25.0,
width: 25.0,
margin: EdgeInsets.only(right: 10.0),
alignment: Alignment.center,
child:
Text('E', style: TextStyle(color: Colors.white))),
if (episode.duration != 0)
episodeTag(
episode.duration == 0
? ''
2022-06-03 16:29:19 +02:00
: s.minsCount(episode.duration! ~/ 60),
2020-12-31 19:08:46 +01:00
Colors.cyan[300]),
if (episode.enclosureLength != null)
episodeTag(
episode.enclosureLength == 0
? ''
2022-04-30 17:16:19 +02:00
: '${episode.enclosureLength! ~/ 1000000}MB',
2020-12-31 19:08:46 +01:00
Colors.lightBlue[300]),
2020-12-20 10:35:39 +01:00
],
),
),
2022-04-30 17:16:19 +02:00
trailing: isPlaying!
2020-12-31 19:08:46 +01:00
? Container(
height: 20,
width: 20,
margin: EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
shape: BoxShape.circle,
),
child: WaveLoader(color: context.accentColor))
: SizedBox(width: 1),
2020-12-20 10:35:39 +01:00
),
2020-12-31 19:08:46 +01:00
),
if (showDivider) Divider(height: 1),
2020-12-31 19:08:46 +01:00
],
),
2020-12-20 10:35:39 +01:00
);
}
}