Skip to content

Commit

Permalink
spotify button working
Browse files Browse the repository at this point in the history
  • Loading branch information
apoleon33 committed Jan 7, 2024
1 parent e39258a commit 73cd7ad
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ One album per day
- [x] deactivate spotify link if it does not exist
- [x] app theme based on today's record
- [ ] working buttons
- [ ] link to spotify
- [x] link to spotify
- [ ] see more (...)
- [x] group as list/as card
- [x] ~~top left menu~~ replaced by a bottom bar
Expand Down
18 changes: 15 additions & 3 deletions lib/albumCard/display_as_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@ import 'package:cradle/album.dart';
import 'package:cradle/albumCard/display_album.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:url_launcher/url_launcher.dart';

import '../moreInfoMenu.dart';

class DisplayAlbumAsCard extends DisplayAlbum {
late Album album;
late DateTime date;
Uri _url = Uri.parse('https://flutter.dev');

DisplayAlbumAsCard({super.key, required this.album, required this.date});
DisplayAlbumAsCard({super.key, required this.album, required this.date}) {
const String initialUrl = "https://open.spotify.com/search/";
String url = Uri.encodeFull('$initialUrl${album.name} - ${album.artist}');
_url = Uri.parse(url);
}

Future<void> _launchUrl() async {
if (!await launchUrl(_url)) {
throw Exception('Could not launch $_url');
}
}

@override
Widget displayAlbum(BuildContext context) {
Expand All @@ -21,7 +33,7 @@ class DisplayAlbumAsCard extends DisplayAlbum {
width: MediaQuery.of(context).size.width - 32,
height: 425,
child: Card(
elevation: (dateIsToday(date))? 1: 0,
elevation: (dateIsToday(date)) ? 1 : 0,
color: Theme.of(context).colorScheme.surfaceVariant,
child: Column(
children: [
Expand Down Expand Up @@ -152,7 +164,7 @@ class DisplayAlbumAsCard extends DisplayAlbum {
width: 18,
height: 18,
),
onPressed: null,
onPressed: _launchUrl,
label: const Text("Listen on Spotify"),
),
],
Expand Down
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:io';

import 'package:cradle/theme_manager.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'route/home.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}

Expand Down
1 change: 1 addition & 0 deletions lib/route/albumCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class _AlbumCardState extends State<AlbumCard> {
? DisplayAlbumAsCard(
album: album,
date: date,
key: ValueKey(album),
)
: DisplayAsList(album: album, date: date);
}
Expand Down
12 changes: 12 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
}
3 changes: 3 additions & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
url_launcher_linux
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
6 changes: 6 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
import FlutterMacOS
import Foundation

import screen_retriever
import shared_preferences_foundation
import url_launcher_macos
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
80 changes: 80 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.1.1"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
sha256: "6ee02c8a1158e6dae7ca430da79436e3b1c9563c8cf02f524af997c201ac2b90"
url: "https://pub.dev"
source: hosted
version: "0.1.9"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -365,6 +373,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
sha256: e9aa5ea75c84cf46b3db4eea212523591211c3cf2e13099ee4ec147f54201c86
url: "https://pub.dev"
source: hosted
version: "6.2.2"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: c0766a55ab42cefaa728cabc951e82919ab41a3a4fee0aaa96176ca82da8cc51
url: "https://pub.dev"
source: hosted
version: "6.2.1"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "46b81e3109cbb2d6b81702ad3077540789a3e74e22795eb9f0b7d494dbaa72ea"
url: "https://pub.dev"
source: hosted
version: "6.2.2"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.dev"
source: hosted
version: "3.1.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
url: "https://pub.dev"
source: hosted
version: "3.1.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "4aca1e060978e19b2998ee28503f40b5ba6226819c2b5e3e4d1821e8ccd92198"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: fff0932192afeedf63cdd50ecbb1bc825d31aed259f02bb8dba0f3b729a5e88b
url: "https://pub.dev"
source: hosted
version: "2.2.3"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.dev"
source: hosted
version: "3.1.1"
vector_graphics:
dependency: transitive
description:
Expand Down Expand Up @@ -413,6 +485,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.2.0"
window_manager:
dependency: "direct main"
description:
name: window_manager
sha256: dcc865277f26a7dad263a47d0e405d77e21f12cb71f30333a52710a408690bd7
url: "https://pub.dev"
source: hosted
version: "0.3.7"
xdg_directories:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ dependencies:
dio:
shared_preferences: ^2.2.2
provider: ^6.1.1
window_manager:
url_launcher:

dev_dependencies:
flutter_test:
Expand Down
9 changes: 9 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
url_launcher_windows
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 73cd7ad

Please sign in to comment.