generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from JothishKamal/dev
feat: error handling, loading states, ui fixes
- Loading branch information
Showing
8 changed files
with
160 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'dart:developer'; | ||
|
||
import 'package:spotify_collab_app/utils/api_util.dart'; | ||
|
||
class CreateScreenNotifier extends StateNotifier<AsyncValue<void>> { | ||
CreateScreenNotifier() : super(const AsyncValue.data(null)); | ||
|
||
Future<({bool success, String message})> createPlaylist(String name) async { | ||
try { | ||
state = const AsyncValue.loading(); | ||
|
||
final response = await apiUtil.post('/v1/playlists', { | ||
'name': name, | ||
}); | ||
|
||
log(response.toString()); | ||
|
||
if (response.statusCode == 200 && | ||
response.data["message"] == "playlist successfully created") { | ||
state = const AsyncValue.data(null); | ||
return (success: true, message: 'Playlist successfully created'); | ||
} | ||
|
||
state = const AsyncValue.data(null); | ||
return (success: false, message: 'Failed to create playlist'); | ||
} catch (e, st) { | ||
state = AsyncValue.error(e, st); | ||
return (success: false, message: 'Failed to create playlist'); | ||
} | ||
} | ||
} | ||
|
||
final createScreenProvider = | ||
StateNotifierProvider<CreateScreenNotifier, AsyncValue<void>>((ref) { | ||
return CreateScreenNotifier(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.