Skip to content

Commit

Permalink
Refactor player controller and update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ahvvad committed Dec 24, 2024
1 parent 463f91d commit 421f60a
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 174 deletions.
Binary file added assets/Launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/splash.png
Binary file not shown.
7 changes: 5 additions & 2 deletions lib/controllers/dialog_contact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import '../consts/colors.dart';
import '../consts/text_style.dart';

class DialogHelper {
static void showLinkDialog({required String url}) {
static void showLinkDialog({
required String url,
required String title,
}) {
Get.defaultDialog(
title: "Open Link",
middleText: "Click the button to contact the developer.",
middleText: title,
backgroundColor: whiteColor,
titleStyle: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
middleTextStyle: const TextStyle(fontSize: 14),
Expand Down
55 changes: 41 additions & 14 deletions lib/controllers/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,39 @@ class PlayerController extends GetxController {
var max = 0.0.obs;
var value = 0.0.obs;

late List<SongModel> data;
var isLoading = true.obs;
List<SongModel> data = [];

@override
void onInit() {
super.onInit();
checkPermission();
loadSongs();

audioPlayer.positionStream.listen((position) {
if (audioPlayer.duration != null && position >= audioPlayer.duration!) {
_playNextSong();
playNextSong();
}
});
}

loadSongs() async {
Future<void> loadSongs() async {
var perm = await Permission.storage.request();
if (perm.isGranted) {
var songs = await audioQuery.querySongs();
data = songs;
data = songs.isNotEmpty ? songs : [];
} else {
print("Permission denied!");
}
isLoading(false);
}

_playNextSong() {
if (playIndex.value < data.length - 1) {
playSong(data[playIndex.value + 1].uri, playIndex.value + 1);
} else {
playSong(data[0].uri, 0);
}
}
// _playNextSong() {
// if (playIndex.value < data.length - 1) {
// playSong(data[playIndex.value + 1].uri, playIndex.value + 1);
// } else {
// playSong(data[0].uri, 0);
// }
// }

updatePosition() {
audioPlayer.durationStream.listen((d) {
Expand Down Expand Up @@ -90,10 +91,36 @@ class PlayerController extends GetxController {
}
}

void playNextSong() {
if (playIndex.value < data.length - 1) {
playSong(data[playIndex.value + 1].uri, playIndex.value + 1);
} else {
playSong(data[0].uri, 0);
}
}

void playPreviousSong() {
if (playIndex.value > 0) {
playSong(data[playIndex.value - 1].uri, playIndex.value - 1);
} else {
playSong(data[data.length - 1].uri, data.length - 1);
}
}


pauseOrResume() {
if (audioPlayer.playing) {
audioPlayer.pause();
isPlaying(false);
} else {
audioPlayer.play();
isPlaying(true);
}
}

checkPermission() async {
var perm = await Permission.storage.request();
if (perm.isGranted) {
} else {
if (!perm.isGranted) {
checkPermission();
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'pages/albums_screen.dart';
import 'pages/home.dart';
import 'pages/playlist_screen.dart';
import 'widgets/drawer.dart';

void main() {
Expand Down Expand Up @@ -34,4 +32,4 @@ class MyApp extends StatelessWidget {
),
);
}
}
}
6 changes: 3 additions & 3 deletions lib/pages/albums_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class _AlbumsScreenState extends State<AlbumsScreen> {
),
child: Scaffold(
appBar: appBar(),
floatingActionButton: FloatBotton(controller: controller),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
// floatingActionButton: FloatBotton(controller: controller),
// floatingActionButtonLocation:
// FloatingActionButtonLocation.centerFloat,
backgroundColor: Colors.transparent,
body: Column(
children: <Widget>[
Expand Down
Loading

0 comments on commit 421f60a

Please sign in to comment.