diff --git a/lib/main.dart b/lib/main.dart index 25ee761..47bfb83 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,4 @@ -import 'dart:async'; - import 'package:flutter/material.dart'; -import 'package:flutter/services.dart' show rootBundle; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:provider/provider.dart'; import 'package:spotkin_flutter/app_core.dart'; @@ -33,21 +30,6 @@ void main() async { ); } -// void main() async { -// WidgetsFlutterBinding.ensureInitialized(); - -// setUrlStrategy(PathUrlStrategy()); -// Map config = await loadConfig(); -// setupServiceLocator(config: config); - -// runApp( -// ChangeNotifierProvider( -// create: (context) => JobProvider(), -// child: MyApp(config), -// ), -// ); -// } - class MyApp extends StatelessWidget { final Map config; diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 2ec66b4..aed0317 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -12,22 +12,6 @@ class SettingsScreen extends StatelessWidget { required this.index, }); - void _createBackup(BuildContext context) { - backupService.createBackup(); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Backup file created. Check your downloads.')), - ); - } - - Future _importBackup(BuildContext context) async { - await backupService.importBackup(); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Backup imported and jobs updated.')), - ); - Provider.of(context, listen: false).loadJobs(); - } - @override Widget build(BuildContext context) { final jobProvider = Provider.of(context, listen: false); @@ -57,30 +41,6 @@ class SettingsScreen extends StatelessWidget { ), ), const SizedBox(height: 16), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - ElevatedButton.icon( - icon: const Icon(Icons.backup), - label: const Text('Create Backup'), - onPressed: () => _createBackup(context), - style: ElevatedButton.styleFrom( - padding: - const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - ), - ), - ElevatedButton.icon( - icon: const Icon(Icons.restore), - label: const Text('Import Backup'), - onPressed: () => _importBackup(context), - style: ElevatedButton.styleFrom( - padding: - const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - ), - ), - ], - ), - const SizedBox(height: 16), ], ), ); diff --git a/lib/widgets/recipe_widget.dart b/lib/widgets/recipe_widget.dart index 833e434..a427a14 100644 --- a/lib/widgets/recipe_widget.dart +++ b/lib/widgets/recipe_widget.dart @@ -209,7 +209,7 @@ class _RecipeWidgetState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.end, children: [ IconButton( icon: const Icon(Icons.add), diff --git a/lib/widgets/target_playlist_selection_options.dart b/lib/widgets/target_playlist_selection_options.dart index 00ed29e..898615f 100644 --- a/lib/widgets/target_playlist_selection_options.dart +++ b/lib/widgets/target_playlist_selection_options.dart @@ -1,6 +1,5 @@ -import 'dart:js'; - import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'package:spotify/spotify.dart'; import 'package:spotkin_flutter/app_core.dart'; @@ -8,27 +7,56 @@ class TargetPlaylistSelectionOptions extends StatelessWidget { final Function(PlaylistSimple) onPlaylistSelected; final PlaylistSimple playlist; final Function() deleteJob; + final StorageService storageService = StorageService(); + late final BackupService backupService; - const TargetPlaylistSelectionOptions({ + TargetPlaylistSelectionOptions({ super.key, required this.onPlaylistSelected, required this.playlist, required this.deleteJob, }); + void _createBackup(BuildContext context) { + backupService.createBackup(); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Backup file created. Check your downloads.')), + ); + } + + Future _importBackup(BuildContext context) async { + await backupService.importBackup(); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Backup imported and jobs updated.')), + ); + Provider.of(context, listen: false).loadJobs(); + } + @override Widget build(BuildContext context) { + final jobProvider = Provider.of(context, listen: false); + + // Initialize backupService here to have access to the context + backupService = BackupService( + storageService, + jobProvider.addJob, + jobProvider.updateJob, + ); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox( height: 24, ), + const Divider(), Text( - 'Select which playlist you want to use for Spotkin', - style: Theme.of(context).textTheme.titleLarge, - textAlign: TextAlign.center, + 'Select which playlist to update with this Spotkin', + style: Theme.of(context).textTheme.titleMedium, ), const SizedBox(height: 24), + Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 250), @@ -41,13 +69,16 @@ class TargetPlaylistSelectionOptions extends StatelessWidget { ), ), ), - const SizedBox(height: 16), - Text( - 'or', - style: Theme.of(context).textTheme.titleMedium, - textAlign: TextAlign.center, + // const SizedBox(height: 16), + Padding( + padding: const EdgeInsets.all(16.0), + child: Text( + 'or', + style: Theme.of(context).textTheme.titleMedium, + textAlign: TextAlign.center, + ), ), - const SizedBox(height: 16), + // const SizedBox(height: 16), Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 250), @@ -56,29 +87,62 @@ class TargetPlaylistSelectionOptions extends StatelessWidget { style: ElevatedButton.styleFrom( minimumSize: const Size(200, 50), ), - child: const Text('Select Existing Playlist'), + child: const Text('Select One of Your Playlists'), ), ), ), - const SizedBox(height: 16), + + const SizedBox(height: 24), + const Divider(), Text( - 'or', + 'Backup and Restore', style: Theme.of(context).textTheme.titleMedium, textAlign: TextAlign.center, ), const SizedBox(height: 16), - Center( - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 250), - child: ElevatedButton( + Row( + children: [ + const Text('Import Backup'), + const Spacer(), + ElevatedButton( + onPressed: () => _importBackup(context), + style: ElevatedButton.styleFrom( + padding: + const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + ), + child: const Icon(Icons.restore), + ), + ], + ), + const SizedBox(height: 16), + Row( + children: [ + const Text('Create Backup'), + const Spacer(), + ElevatedButton( + onPressed: () => _createBackup(context), + style: ElevatedButton.styleFrom( + padding: + const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + ), + child: const Icon(Icons.backup), + ), + ], + ), + const SizedBox(height: 24), + Row( + children: [ + const Text('Delete this Spotkin'), + const Spacer(), + ElevatedButton( onPressed: () => deleteJob(), style: ElevatedButton.styleFrom( - minimumSize: const Size(200, 50), + minimumSize: const Size(50, 50), backgroundColor: Colors.red, ), - child: const Text('Delete this Spotkin'), + child: const Icon(Icons.delete), ), - ), + ], ), const SizedBox(height: 24), ], diff --git a/lib/widgets/target_playlist_widget.dart b/lib/widgets/target_playlist_widget.dart index 5d63385..9e0f73f 100644 --- a/lib/widgets/target_playlist_widget.dart +++ b/lib/widgets/target_playlist_widget.dart @@ -100,7 +100,7 @@ class TargetPlaylistWidget extends StatelessWidget { top: 0, right: 0, child: IconButton( - icon: Icon(isExpanded ? Icons.edit_off : Icons.edit), + icon: const Icon(Icons.settings), onPressed: () { onExpandChanged(!isExpanded); },