fooder-app/lib/screens/based.dart

126 lines
3.3 KiB
Dart
Raw Normal View History

2023-07-29 18:10:10 +02:00
import 'package:flutter/material.dart';
2023-07-30 15:31:36 +02:00
import 'package:fooder/client.dart';
2024-03-30 14:07:10 +01:00
import 'package:fooder/components/app_bar.dart';
import 'package:fooder/components/navigation_bar.dart';
2024-03-29 16:47:25 +01:00
import 'package:fooder/screens/login.dart';
import 'package:fooder/screens/main.dart';
2023-07-29 18:10:10 +02:00
2023-10-27 13:48:45 +02:00
TextStyle logoStyle(context) {
return Theme.of(context).textTheme.labelLarge!.copyWith(
color: Theme.of(context).colorScheme.secondary,
);
}
2023-07-29 18:10:10 +02:00
abstract class BasedScreen extends StatefulWidget {
final ApiClient apiClient;
const BasedScreen({super.key, required this.apiClient});
2024-03-28 16:25:49 +01:00
}
abstract class BasedState<T extends BasedScreen> extends State<T> {
2024-03-29 16:47:25 +01:00
void _logout() async {
await widget.apiClient.logout();
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => LoginScreen(apiClient: widget.apiClient),
),
);
}
void backToDiary() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => MainScreen(apiClient: widget.apiClient),
),
);
}
FAppBar appBar() {
return FAppBar(
actions: [
IconButton(
icon: Icon(
Icons.logout,
2024-04-04 19:03:41 +02:00
color: Theme.of(context).colorScheme.onSurfaceVariant,
2024-03-29 16:47:25 +01:00
),
onPressed: _logout,
),
],
);
}
FNavBar navBar() {
return FNavBar(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
icon: Icon(
Icons.menu_book,
2024-04-04 19:03:41 +02:00
color: Theme.of(context).colorScheme.onSurfaceVariant,
2024-03-29 16:47:25 +01:00
),
onPressed: backToDiary,
),
IconButton(
icon: Icon(
Icons.dinner_dining,
2024-04-04 19:03:41 +02:00
color: Theme.of(context).colorScheme.onSurfaceVariant,
2024-03-29 16:47:25 +01:00
),
2024-03-30 14:07:10 +01:00
onPressed: () {},
2024-03-29 16:47:25 +01:00
),
IconButton(
icon: Icon(
Icons.lunch_dining,
2024-04-04 19:03:41 +02:00
color: Theme.of(context).colorScheme.onSurfaceVariant,
2024-03-29 16:47:25 +01:00
),
2024-03-30 14:07:10 +01:00
onPressed: () {},
2024-03-29 16:47:25 +01:00
),
IconButton(
icon: Icon(
Icons.person,
2024-04-04 19:03:41 +02:00
color: Theme.of(context).colorScheme.onSurfaceVariant,
2024-03-29 16:47:25 +01:00
),
2024-03-30 14:07:10 +01:00
onPressed: () {},
2024-03-29 16:47:25 +01:00
),
],
),
],
);
}
2024-03-28 16:25:49 +01:00
void showError(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
message,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
2024-03-30 14:07:10 +01:00
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onError,
),
2024-03-28 16:25:49 +01:00
),
2024-03-29 16:47:25 +01:00
backgroundColor: Theme.of(context).colorScheme.error.withOpacity(0.8),
2024-03-28 16:25:49 +01:00
),
);
}
2023-10-27 13:48:45 +02:00
2024-03-28 16:25:49 +01:00
void showText(String text) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
text,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
2024-03-30 14:07:10 +01:00
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onPrimary,
),
2024-03-28 16:25:49 +01:00
),
2024-03-29 16:47:25 +01:00
backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.8),
2024-03-28 16:25:49 +01:00
),
);
}
2023-07-29 18:10:10 +02:00
}