Skip to content

Commit

Permalink
reformat targetplaylistselcetionoptions
Browse files Browse the repository at this point in the history
  • Loading branch information
riverscuomo committed Aug 22, 2024
1 parent 7d516d8 commit 83e373c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 82 deletions.
18 changes: 0 additions & 18 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -33,21 +30,6 @@ void main() async {
);
}

// void main() async {
// WidgetsFlutterBinding.ensureInitialized();

// setUrlStrategy(PathUrlStrategy());
// Map<String, dynamic> config = await loadConfig();
// setupServiceLocator(config: config);

// runApp(
// ChangeNotifierProvider(
// create: (context) => JobProvider(),
// child: MyApp(config),
// ),
// );
// }

class MyApp extends StatelessWidget {
final Map<String, dynamic> config;

Expand Down
40 changes: 0 additions & 40 deletions lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> _importBackup(BuildContext context) async {
await backupService.importBackup();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Backup imported and jobs updated.')),
);
Provider.of<JobProvider>(context, listen: false).loadJobs();
}

@override
Widget build(BuildContext context) {
final jobProvider = Provider.of<JobProvider>(context, listen: false);
Expand Down Expand Up @@ -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),
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/recipe_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class _RecipeWidgetState extends State<RecipeWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
icon: const Icon(Icons.add),
Expand Down
108 changes: 86 additions & 22 deletions lib/widgets/target_playlist_selection_options.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
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';

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<void> _importBackup(BuildContext context) async {
await backupService.importBackup();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Backup imported and jobs updated.')),
);
Provider.of<JobProvider>(context, listen: false).loadJobs();
}

@override
Widget build(BuildContext context) {
final jobProvider = Provider.of<JobProvider>(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),
Expand All @@ -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),
Expand All @@ -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),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/target_playlist_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down

0 comments on commit 83e373c

Please sign in to comment.