fApp/lib/widgets/end_drawer.dart
Flummi ee2db04a36
All checks were successful
Flutter Schmutter / build (push) Successful in 3m47s
v1.3.3+59
2025-06-17 19:03:40 +02:00

146 lines
4.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:f0ckapp/screens/login_screen.dart';
import 'package:f0ckapp/controller/auth_controller.dart';
import 'package:f0ckapp/screens/settings_screen.dart';
import 'package:f0ckapp/controller/theme_controller.dart';
import 'package:f0ckapp/utils/appversion.dart';
class EndDrawer extends StatelessWidget {
const EndDrawer({super.key});
void _showMsg(String message, {String title = ''}) {
Get
..closeAllSnackbars()
..snackbar(message, title, snackPosition: SnackPosition.BOTTOM);
}
@override
Widget build(BuildContext context) {
final ThemeController themeController = Get.find();
final AuthController authController = Get.find();
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
Obx(() {
if (authController.token.value != null &&
authController.avatarUrl.value != null) {
return DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(authController.avatarUrl.value!),
fit: BoxFit.cover,
alignment: Alignment.topCenter,
),
),
child: null,
);
} else {
return DrawerHeader(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/menu.webp'),
fit: BoxFit.cover,
alignment: Alignment.topCenter,
),
),
child: null,
);
}
}),
Obx(() {
if (authController.token.value != null) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
if (authController.username.value != null)
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
'Hamlo ${authController.username.value!}',
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
ElevatedButton(
onPressed: () async {
await authController.logout();
_showMsg('Erfolgreich ausgeloggt.');
},
child: const Text('Logout'),
),
],
),
);
} else {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Text(
'Du bist nicht eingeloggt.',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () {
Navigator.pop(context);
Get.bottomSheet(LoginPage(), isDismissible: false);
},
child: const Text('Login'),
),
],
),
);
}
}),
ExpansionTile(
title: const Text('Theme'),
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Obx(() {
return Column(
children: themeController.themeMap.entries.map((entry) {
final String themeName = entry.key;
final ThemeData themeData = entry.value;
final bool isSelected =
themeController.currentTheme.value == themeData;
return ListTile(
title: Text(themeName),
selected: isSelected,
selectedTileColor: Colors.blue.withValues(alpha: 0.2),
onTap: () async {
await themeController.updateTheme(themeName);
},
);
}).toList(),
);
}),
),
],
),
ListTile(
title: const Text('Settings'),
onTap: () {
Navigator.pop(context);
Get.bottomSheet(SettingsPage());
},
),
ListTile(
title: Text('v${AppVersion.version}'),
onTap: () {
Navigator.pop(context);
_showMsg('jooong lass das, hier ist nichts');
},
),
],
),
);
}
}