diff --git a/README.md b/README.md index 4dbc719..690b674 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/albumCard/display_as_card.dart b/lib/albumCard/display_as_card.dart index d30e000..06aa70f 100644 --- a/lib/albumCard/display_as_card.dart +++ b/lib/albumCard/display_as_card.dart @@ -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 _launchUrl() async { + if (!await launchUrl(_url)) { + throw Exception('Could not launch $_url'); + } + } @override Widget displayAlbum(BuildContext context) { @@ -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: [ @@ -152,7 +164,7 @@ class DisplayAlbumAsCard extends DisplayAlbum { width: 18, height: 18, ), - onPressed: null, + onPressed: _launchUrl, label: const Text("Listen on Spotify"), ), ], diff --git a/lib/main.dart b/lib/main.dart index 9fb504c..3df5981 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:cradle/theme_manager.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -5,6 +7,7 @@ import 'package:provider/provider.dart'; import 'route/home.dart'; void main() async { + WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); } diff --git a/lib/route/albumCard.dart b/lib/route/albumCard.dart index 335e616..ec17b38 100644 --- a/lib/route/albumCard.dart +++ b/lib/route/albumCard.dart @@ -63,6 +63,7 @@ class _AlbumCardState extends State { ? DisplayAlbumAsCard( album: album, date: date, + key: ValueKey(album), ) : DisplayAsList(album: album, date: date); } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e71a16d..0cacc75 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,18 @@ #include "generated_plugin_registrant.h" +#include +#include +#include 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); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..62f151f 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,9 @@ # list(APPEND FLUTTER_PLUGIN_LIST + screen_retriever + url_launcher_linux + window_manager ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 724bb2a..e180b20 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -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")) } diff --git a/pubspec.lock b/pubspec.lock index d425cd0..f8e7746 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 1ed8344..cfa966e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,6 +40,8 @@ dependencies: dio: shared_preferences: ^2.2.2 provider: ^6.1.1 + window_manager: + url_launcher: dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..fe7ec1c 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,15 @@ #include "generated_plugin_registrant.h" +#include +#include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + ScreenRetrieverPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); + UrlLauncherWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("UrlLauncherWindows")); + WindowManagerPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("WindowManagerPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..fb2dea6 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,9 @@ # list(APPEND FLUTTER_PLUGIN_LIST + screen_retriever + url_launcher_windows + window_manager ) list(APPEND FLUTTER_FFI_PLUGIN_LIST