Skip to content

Commit

Permalink
play button
Browse files Browse the repository at this point in the history
  • Loading branch information
riverscuomo committed Jul 31, 2024
1 parent 4dca045 commit 56ade57
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 44 deletions.
10 changes: 6 additions & 4 deletions lib/helpers/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:spotify/spotify.dart' hide Image;
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher.dart' as url_launcher;

class Utils {
static String extractPlaylistId(String playlistUrl) {
Expand All @@ -22,9 +22,11 @@ class Utils {
: const Icon(Icons.music_note);
}

static void launchUrl(String url) async {
if (await canLaunchUrl(Uri.parse(url))) {
launchUrl(url);
static Future<void> myLaunch(String url) async {
print('Launching URL: $url');
final uri = Uri.parse(url);
if (await url_launcher.canLaunchUrl(uri)) {
await url_launcher.launchUrl(uri);
} else {
throw 'Could not launch $url';
}
Expand Down
23 changes: 21 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,28 @@ final spotifyThemeData = ThemeData(
titleTextStyle: TextStyle(
color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
),
buttonTheme: ButtonThemeData(
buttonColor: Colors.green,
textTheme: ButtonTextTheme.primary,
// padding: const EdgeInsets.all(16.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
),
// iconButtonTheme: IconButtonThemeData(
// style: ButtonStyle(
// backgroundColor: MaterialStateProperty.all(Colors.green),
// foregroundColor: MaterialStateProperty.all(Colors.black),
// overlayColor: MaterialStateProperty.all(Colors.green[700]),
// shape: MaterialStateProperty.all(CircleBorder()),
// padding: MaterialStateProperty.all(EdgeInsets.all(12)),
// minimumSize: MaterialStateProperty.all(Size(48, 48)),
// ),
// ),
textTheme: TextTheme(
titleLarge: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
bodyMedium: TextStyle(color: Colors.white70),
titleLarge:
const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
bodyMedium: const TextStyle(color: Colors.white70),
// titleMedium: TextStyle(color: Colors.white54),
labelMedium: TextStyle(color: Colors.grey[400]),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/models/job.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Job {
'playlist_id': targetPlaylist.id,
'description': description,
'remove_low_energy': removeLowEnergy,
'last_tracks': lastTracks,
'last_track_ids': lastTracks.map((t) => t.id).toList(),
'banned_artists': bannedArtists,
// 'banned_song_titles': bannedSongTitles,
'banned_tracks': bannedTracks,
Expand Down
73 changes: 41 additions & 32 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class _HomeScreenState extends State<HomeScreen> {
});
}

Widget _buildPlaylistSelectionOptions() {
return PlaylistSelectionOptions(
Widget _buildTargetPlaylistSelectionOptions() {
return TargetPlaylistSelectionOptions(
onPlaylistSelected: (PlaylistSimple selectedPlaylist) {
if (jobs.isEmpty) {
final newJob = Job(
Expand Down Expand Up @@ -181,7 +181,7 @@ class _HomeScreenState extends State<HomeScreen> {
Column(
children: [
// jobs.isEmpty || _isResettingTargetPlaylist
// ? _buildPlaylistSelectionOptions()
// ? _buildTargetPlaylistSelectionOptions()
// :
ExpansionTile(
title: PlaylistTitle(context, targetPlaylist),
Expand All @@ -190,7 +190,7 @@ class _HomeScreenState extends State<HomeScreen> {
initiallyExpanded: jobs.isEmpty,

children: [
_buildPlaylistSelectionOptions(),
_buildTargetPlaylistSelectionOptions(),
],

// playlist: targetPlaylist,
Expand Down Expand Up @@ -234,6 +234,14 @@ class _HomeScreenState extends State<HomeScreen> {
? Colors.green
: Colors.red,
),
trailing: IconButton(
icon: const Icon(Icons.play_arrow),
style: greenButtonStyle,
onPressed: () {
Utils.myLaunch(
targetPlaylist.externalUrls?.spotify ?? '');
},
),
);
}),
]),
Expand All @@ -242,20 +250,33 @@ class _HomeScreenState extends State<HomeScreen> {
),
),
bottomNavigationBar: jobs.isNotEmpty && jobs[0].recipe.isNotEmpty
? Padding(
? Container(
padding: const EdgeInsets.all(16),
child: ElevatedButton(
onPressed: isProcessing ? null : _processJobs,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
child: SafeArea(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 300, // Adjust this value as needed
minHeight: 50,
),
child: ElevatedButton(
onPressed: isProcessing ? null : _processJobs,
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50), // Minimum size
padding: const EdgeInsets.symmetric(horizontal: 20),
),
child: Text(
isProcessing
? 'Processing...'
: 'Update Spotkin On Spotify',
textAlign: TextAlign.center,
),
),
),
],
),
child: Text(isProcessing
? 'Processing...'
: 'Update Spotkin On Spotify'),
),
)
: null,
Expand All @@ -264,19 +285,7 @@ class _HomeScreenState extends State<HomeScreen> {
}
}

Widget playlistSubtitle(PlaylistSimple playlist, BuildContext context) {
return playlist.owner != null
? Text(
'Playlist • ${playlist.owner!.displayName}',
style: Theme.of(context).textTheme.labelMedium,
)
: const SizedBox();
}

Text PlaylistTitle(BuildContext context, PlaylistSimple playlist) {
return Text(
playlist.name ?? 'Unknown Playlist',
style: Theme.of(context).textTheme.titleMedium,
overflow: TextOverflow.ellipsis,
);
}
var greenButtonStyle = ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green),
foregroundColor: MaterialStateProperty.all(Colors.black),
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:spotify/spotify.dart';
import 'package:spotkin_flutter/app_core.dart';

class PlaylistNameField extends StatelessWidget {
Expand Down Expand Up @@ -27,3 +28,20 @@ class PlaylistNameField extends StatelessWidget {
);
}
}

Widget playlistSubtitle(PlaylistSimple playlist, BuildContext context) {
return playlist.owner != null
? Text(
'Playlist • ${playlist.owner!.displayName}',
style: Theme.of(context).textTheme.labelMedium,
)
: const SizedBox();
}

Text PlaylistTitle(BuildContext context, PlaylistSimple playlist) {
return Text(
playlist.name ?? 'Unknown Playlist',
style: Theme.of(context).textTheme.titleMedium,
overflow: TextOverflow.ellipsis,
);
}
2 changes: 1 addition & 1 deletion lib/widgets/spotify_style_playlist_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SpotifyStylePlaylistTile extends StatelessWidget {
onTap: () {
final url = playlist.externalUrls!.spotify;
if (url != null) {
Utils.launchUrl(url);
Utils.myLaunch(url);
}
},
child: Padding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
import 'package:spotify/spotify.dart';
import 'package:spotkin_flutter/app_core.dart';

class PlaylistSelectionOptions extends StatelessWidget {
class TargetPlaylistSelectionOptions extends StatelessWidget {
final Function(PlaylistSimple) onPlaylistSelected;

const PlaylistSelectionOptions({
const TargetPlaylistSelectionOptions({
Key? key,
required this.onPlaylistSelected,
}) : super(key: key);
Expand All @@ -19,7 +19,7 @@ class PlaylistSelectionOptions extends StatelessWidget {
height: 24,
),
Text(
'Step 1: Select which playlist you want to use for your Spotkin',
'Step 1: Select which playlist you want to use for Spotkin',
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export 'ingredient_form.dart';
export 'bottom_sheets/bottom_sheets.dart';
export 'playlist_selection_options.dart';
export 'playlist_widgets.dart';
export 'target_playlist_selection_options.dart';
export 'settings_card.dart';
export 'spotify_style_playlist_tile.dart';

0 comments on commit 56ade57

Please sign in to comment.