Preview for audio and images, better asset table
This commit is contained in:
parent
a4ab10db17
commit
bce8e97368
4 changed files with 196 additions and 173 deletions
72
lib/widgets/audio_player_widget.dart
Normal file
72
lib/widgets/audio_player_widget.dart
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
|
||||
class AudioPlayerWidgetController extends GetxController {
|
||||
final String title;
|
||||
final String url;
|
||||
|
||||
AudioPlayerWidgetController({
|
||||
required this.title,
|
||||
required this.url,
|
||||
});
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
player = AudioPlayer();
|
||||
player.play(UrlSource(url));
|
||||
|
||||
player.onPlayerStateChanged.listen((event) {
|
||||
_playerState.value = event;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
player.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
late AudioPlayer player;
|
||||
|
||||
final _playerState = PlayerState.stopped.obs;
|
||||
get playerState => _playerState.value;
|
||||
}
|
||||
|
||||
class AudioPlayerWidget extends GetView<AudioPlayerWidgetController> {
|
||||
const AudioPlayerWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Obx(
|
||||
() => controller.playerState == PlayerState.playing
|
||||
? IconButton(
|
||||
onPressed: () => controller.player.pause(),
|
||||
icon: const Icon(Icons.pause),
|
||||
)
|
||||
: IconButton(
|
||||
onPressed: () => controller.player.resume(),
|
||||
icon: const Icon(Icons.play_arrow),
|
||||
),
|
||||
),
|
||||
title: const Text("Playing"),
|
||||
subtitle: Text(controller.title),
|
||||
).card().paddingAll(16).center();
|
||||
}
|
||||
|
||||
static AudioPlayerWidget create(
|
||||
{required String url, required String title}) {
|
||||
Get.lazyPut<AudioPlayerWidgetController>(
|
||||
() => AudioPlayerWidgetController(
|
||||
title: title,
|
||||
url: url,
|
||||
),
|
||||
);
|
||||
|
||||
return const AudioPlayerWidget();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue