mucke/lib/presentation/widgets/play_pause_button.dart

48 lines
1.4 KiB
Dart
Raw Normal View History

2020-04-10 20:12:26 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:provider/provider.dart';
import '../../domain/entities/playback_state.dart';
import '../state/audio_store.dart';
class PlayPauseButton extends StatelessWidget {
2020-08-24 12:01:01 +02:00
const PlayPauseButton({Key key, this.circle = false, this.iconSize = 24.0})
: super(key: key);
2020-04-10 20:12:26 +02:00
final bool circle;
final double iconSize;
@override
Widget build(BuildContext context) {
final AudioStore audioStore = Provider.of<AudioStore>(context);
return Observer(
builder: (BuildContext context) {
switch (audioStore.playbackStateStream.value) {
case PlaybackState.playing:
return IconButton(
2020-08-24 12:01:01 +02:00
icon: circle
2020-12-31 17:52:20 +01:00
? const Icon(Icons.pause_circle_filled_rounded)
: const Icon(Icons.pause_rounded),
2020-04-10 20:12:26 +02:00
iconSize: iconSize,
onPressed: () {
audioStore.pause();
},
);
case PlaybackState.paused:
2020-08-24 12:01:01 +02:00
default:
2020-04-10 20:12:26 +02:00
return IconButton(
2020-08-24 12:01:01 +02:00
icon: circle
2020-12-31 17:52:20 +01:00
? const Icon(Icons.play_circle_filled_rounded)
: const Icon(Icons.play_arrow_rounded),
2020-04-10 20:12:26 +02:00
iconSize: iconSize,
onPressed: () {
audioStore.play();
},
);
}
},
);
}
}