Aplikacja_mobilna/cookbook/lib/screens/home_screen/home_screen.dart

154 lines
6.0 KiB
Dart

import 'package:cookbook/screens/home_screen/home_controller.dart';
import 'package:flutter/material.dart';
import 'package:cookbook/screens/create_recipe_screen/createrecipe_screen.dart';
import 'package:cookbook/screens/favorites_screen/favorites_screen.dart';
import 'package:cookbook/screens/recipe_search/search_screen.dart';
import 'package:cookbook/screens/my_recipes_screen/my_recipes_screen.dart';
import 'package:get/get.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
final homecontroller = Get.find<HomeController>();
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.orange,
title: const Text("Home", style: TextStyle(color: Colors.white),),
actions: [
IconButton(
icon: const Icon(Icons.login),
onPressed: () {
homecontroller.signIn();
},),
IconButton(
icon: const Icon(Icons.logout),
onPressed: () {
homecontroller.signOut();
} ,)
],
),
body: SafeArea(
child: Stack(
children: <Widget>[
const FractionallySizedBox(
heightFactor: 1.0,
widthFactor: 1.0,
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("img/background.jpg"),
fit: BoxFit.fill,
),
),
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: 200.0,
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SearchScreen()),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
textStyle: const TextStyle(fontSize: 20.0),
),
child: const Text('Recipe Search'),
),
),
SizedBox(
width: 200.0,
child: ElevatedButton(
onPressed: () {
if (!homecontroller.isUserLoggedIn){
Get.snackbar(
'Warning',
'Please log in to access this page',
snackPosition: SnackPosition.TOP,
);
} else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CreateRecipeScreen()),
);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
textStyle: const TextStyle(fontSize: 20.0),
),
child: const Text('Add recipe'),
),
),
SizedBox(
width: 200.0,
child: ElevatedButton(
onPressed: () {
if (!homecontroller.isUserLoggedIn){
Get.snackbar(
'Warning',
'Please log in to access this page',
snackPosition: SnackPosition.TOP,
);
} else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => FavoritesScreen()),
);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
textStyle: const TextStyle(fontSize: 20.0),
),
child: const Text('Favorites'),
),
),
SizedBox(
width: 200.0,
child: ElevatedButton(
onPressed: () {
if (!homecontroller.isUserLoggedIn){
Get.snackbar(
'Warning',
'Please log in to access this page',
snackPosition: SnackPosition.TOP,
);
} else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MyRecipesScreen()),
);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
textStyle: const TextStyle(fontSize: 20.0),
),
child: const Text('My Recipes'),
),
),
],
),
),
],
),
),
),
);
}
}