Compare commits

...

2 Commits

Author SHA1 Message Date
de8d898289
Fix sign-in, title bar, formatting 2024-08-27 08:21:15 +02:00
e996702408
Implement deleting favorites on frontend 2024-08-27 08:17:48 +02:00
3 changed files with 121 additions and 97 deletions

View File

@ -67,10 +67,8 @@ Future<bool> isLoggedIn(BuildContext context) async {
final prefs = await SharedPreferences.getInstance();
final token = prefs.getString('token');
if (token == null){
if (token == null) {
prefs.remove('id');
loggedIn = false;
user = User as User?;
return false;
}

View File

@ -52,21 +52,16 @@ class _SideMenuState extends State<SideMenu> {
}
@override
Widget build(BuildContext context) {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Row(
children: [
const SizedBox(width: 55),
Text('SkanTravels',
title: Text('SkanTravels',
style: GoogleFonts.jacquesFrancois(
fontSize: 30,
color: Colors.black,
),
),
],
),
),
drawer: Drawer(
child: ListView(
@ -148,5 +143,5 @@ Widget build(BuildContext context) {
),
body: widget.body,
);
}
}
}

View File

@ -14,6 +14,34 @@ class FavoritesPage extends StatefulWidget {
class _FavoritesPage extends State<FavoritesPage> {
List<Favorite> _favorites = [];
void _confirmDeleteFavorite(Favorite favorite) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Remove favorite'),
content: Text('Are you sure you want to remove ${favorite.name} from your favorites list?'),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
TextButton(onPressed: () => _deleteFavorite(favorite), child: const Text('Remove', style: TextStyle(color: Colors.red))),
],
);
}
);
}
void _deleteFavorite(Favorite favorite) async {
Navigator.pop(context);
if (await api.request(context, api.ApiService.app, 'DELETE', '/favorites/${favorite.id}', null) == null) {
return;
}
setState(() {
_favorites = _favorites.where((fav) => fav.id != favorite.id).toList();
});
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
@ -57,7 +85,10 @@ class _FavoritesPage extends State<FavoritesPage> {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(padding: EdgeInsets.only(top: 3), child: Icon(Icons.star, color: Colors.yellow, size: 36)),
const Padding(
padding: EdgeInsets.only(top: 3),
child: Icon(Icons.star, color: Colors.yellow, size: 36)
),
const SizedBox(width: 20),
Expanded(
child: Column(
@ -69,7 +100,7 @@ class _FavoritesPage extends State<FavoritesPage> {
),
),
const SizedBox(width: 20),
const Padding(padding: EdgeInsets.only(top: 5), child: Icon(Icons.delete, color: Colors.grey)),
IconButton(icon: const Icon(Icons.delete), color: Colors.grey, onPressed: () => _confirmDeleteFavorite(favorite)),
],
),
)).toList(),