2020-12-31 17:52:20 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../../domain/entities/song.dart';
|
|
|
|
import '../state/audio_store.dart';
|
|
|
|
import '../state/music_data_store.dart';
|
|
|
|
import '../theming.dart';
|
|
|
|
|
|
|
|
class LikeButton extends StatelessWidget {
|
|
|
|
const LikeButton({Key key, this.iconSize = 20.0}) : super(key: key);
|
|
|
|
|
|
|
|
final double iconSize;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final MusicDataStore musicDataStore = Provider.of<MusicDataStore>(context);
|
|
|
|
final AudioStore audioStore = Provider.of<AudioStore>(context);
|
|
|
|
|
|
|
|
return Observer(
|
|
|
|
builder: (BuildContext context) {
|
2021-02-06 14:00:04 +01:00
|
|
|
final Song song = audioStore.currentSongStream.value;
|
2020-12-31 17:52:20 +01:00
|
|
|
|
|
|
|
if (song.likeCount == 0) {
|
|
|
|
return IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.favorite_rounded,
|
|
|
|
size: iconSize,
|
|
|
|
color: Colors.white24,
|
|
|
|
),
|
2021-01-09 19:55:56 +01:00
|
|
|
onPressed: () => musicDataStore.incrementLikeCount(song),
|
2020-12-31 17:52:20 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return IconButton(
|
|
|
|
icon: Stack(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.favorite_rounded,
|
2021-01-27 18:13:21 +01:00
|
|
|
color: Theme.of(context).accentColor,
|
2020-12-31 17:52:20 +01:00
|
|
|
size: iconSize,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
song.likeCount.toString(),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: DARK1,
|
|
|
|
fontSize: 10.0,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
alignment: AlignmentDirectional.center,
|
|
|
|
),
|
2021-01-09 19:55:56 +01:00
|
|
|
onPressed: () {
|
|
|
|
if (song.likeCount < 5) {
|
|
|
|
return musicDataStore.incrementLikeCount(song);
|
|
|
|
}
|
|
|
|
return musicDataStore.resetLikeCount(song);
|
|
|
|
},
|
2020-12-31 17:52:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|