add home page and navigation
This commit is contained in:
parent
212f5726db
commit
3aa7610867
BIN
assets/img/backgroundLogoInternorm.jpg
Normal file
BIN
assets/img/backgroundLogoInternorm.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 411 KiB |
32
lib/controllers/home_controller.dart
Normal file
32
lib/controllers/home_controller.dart
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
|
import '../pages/login/login_view.dart';
|
||||||
|
import '../services/appwrite_service.dart';
|
||||||
|
|
||||||
|
class HomeController extends GetxController {
|
||||||
|
final szHeaderHome = 'Home Page'.obs;
|
||||||
|
late AppWriteProvider appwriteProvider;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
appwriteProvider = AppWriteProvider();
|
||||||
|
super.onInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onReady() {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {}
|
||||||
|
|
||||||
|
void goToLoginPage() async {
|
||||||
|
if (await appwriteProvider.logout()) {
|
||||||
|
Get.snackbar(
|
||||||
|
'Logout Successful',
|
||||||
|
'You have been logged out successfully.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
await Get.offAllNamed(LoginPage.namedRoute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
import 'package:appwrite/models.dart';
|
import 'package:appwrite/models.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_template_getx_provider/services/appwrite_service.dart';
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
|
import '../pages/home/home_view.dart';
|
||||||
|
import '../services/appwrite_service.dart';
|
||||||
|
|
||||||
class LoginController extends GetxController {
|
class LoginController extends GetxController {
|
||||||
final szHeaderLogin = 'Login Page'.obs;
|
final szHeaderLogin = 'Login Page'.obs;
|
||||||
final szHeaderSignin = 'Signin Page'.obs;
|
final szHeaderSignin = 'Signin Page'.obs;
|
||||||
@ -65,6 +67,8 @@ class LoginController extends GetxController {
|
|||||||
'You have been logged in successfully.',
|
'You have been logged in successfully.',
|
||||||
snackPosition: SnackPosition.BOTTOM,
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
);
|
);
|
||||||
|
// Navigate to home or another page if needed
|
||||||
|
_goToHomePage();
|
||||||
} else {
|
} else {
|
||||||
Get.snackbar(
|
Get.snackbar(
|
||||||
'Login Failed',
|
'Login Failed',
|
||||||
@ -142,4 +146,8 @@ class LoginController extends GetxController {
|
|||||||
}
|
}
|
||||||
return isLoggedOut;
|
return isLoggedOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _goToHomePage() async {
|
||||||
|
await Get.offAllNamed(HomePage.namedRoute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
|
import '../controllers/home_controller.dart';
|
||||||
import '../controllers/login_controller.dart';
|
import '../controllers/login_controller.dart';
|
||||||
|
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ class SampleBindings extends Bindings {
|
|||||||
void dependencies() {
|
void dependencies() {
|
||||||
// Define your dependencies here
|
// Define your dependencies here
|
||||||
Get.lazyPut<LoginController>(() => LoginController());
|
Get.lazyPut<LoginController>(() => LoginController());
|
||||||
|
Get.lazyPut<HomeController>(() => HomeController());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import '../pages/home/home_view.dart';
|
||||||
import '../pages/login/login_view.dart';
|
import '../pages/login/login_view.dart';
|
||||||
import './sample_bindings.dart';
|
import './sample_bindings.dart';
|
||||||
|
|
||||||
@ -13,6 +14,11 @@ class SampleRouts {
|
|||||||
page: () => const LoginPage(),
|
page: () => const LoginPage(),
|
||||||
binding: sampleBindings,
|
binding: sampleBindings,
|
||||||
),
|
),
|
||||||
|
GetPage(
|
||||||
|
name: HomePage.namedRoute,
|
||||||
|
page: () => const HomePage(),
|
||||||
|
binding: sampleBindings,
|
||||||
|
),
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
0
lib/models/home_model.dart
Normal file
0
lib/models/home_model.dart
Normal file
49
lib/pages/home/home_view.dart
Normal file
49
lib/pages/home/home_view.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import '../../controllers/home_controller.dart';
|
||||||
|
|
||||||
|
class HomePage extends GetView<HomeController> {
|
||||||
|
static const String namedRoute = '/home';
|
||||||
|
const HomePage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var homeCtrl = controller;
|
||||||
|
return PopScope(
|
||||||
|
canPop: false,
|
||||||
|
child: SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.grey.shade500,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: Icon(Icons.arrow_back, color: Colors.grey.shade200),
|
||||||
|
onPressed: () {
|
||||||
|
// Verhindert das Zurücknavigieren
|
||||||
|
homeCtrl.goToLoginPage();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
homeCtrl.szHeaderHome.value,
|
||||||
|
style: TextStyle(color: Colors.grey.shade200),
|
||||||
|
),
|
||||||
|
centerTitle: true,
|
||||||
|
),
|
||||||
|
body: Container(
|
||||||
|
decoration: BoxDecoration(color: Colors.grey.shade400),
|
||||||
|
padding: EdgeInsets.all(20),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'You are on the Home Page...\nPress the back arrow to logout.\nThis is a Template to use...',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey.shade800,
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +0,0 @@
|
|||||||
import 'package:get/get.dart';
|
|
||||||
import '../../controllers/login_controller.dart';
|
|
||||||
|
|
||||||
class LoginBinding extends Bindings {
|
|
||||||
@override
|
|
||||||
void dependencies() {
|
|
||||||
Get.lazyPut<LoginController>(() => LoginController());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -9,52 +9,96 @@ class LoginPage extends GetView<LoginController> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var loginCtrl = controller;
|
var loginCtrl = controller;
|
||||||
|
|
||||||
|
// LayoutBuilder ermöglicht dynamische Anpassung an verschiedene Bildschirmgrößen.
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
body: Center(
|
body: LayoutBuilder(
|
||||||
child: SingleChildScrollView(
|
builder: (context, constraints) {
|
||||||
|
final bool isSmall = constraints.maxWidth < 600;
|
||||||
|
final double cardWidth = isSmall
|
||||||
|
? constraints.maxWidth * 0.92
|
||||||
|
: (constraints.maxWidth * 0.6).clamp(0, 900);
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
// Hintergrundbild skaliert responsiv mit BoxFit.cover
|
||||||
|
Positioned.fill(
|
||||||
|
child: Image.asset(
|
||||||
|
'img/backgroundLogoInternorm.jpg',
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// halbtransparente Ebene; Opazität an Bildschirmgröße anpassen
|
||||||
|
Positioned.fill(
|
||||||
child: Container(
|
child: Container(
|
||||||
width: Get.width * 0.6,
|
color: Colors.black.withAlpha(isSmall ? 50 : 100),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: PopScope(
|
||||||
|
canPop: false,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 250),
|
||||||
|
width: cardWidth,
|
||||||
padding: const EdgeInsets.all(40.0),
|
padding: const EdgeInsets.all(40.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
color: const Color.fromARGB(64, 189, 189, 189),
|
color: const Color.fromARGB(223, 189, 189, 189),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white.withAlpha(150),
|
color: Colors.white.withAlpha(200),
|
||||||
borderRadius: BorderRadius.circular(100),
|
borderRadius: BorderRadius.circular(100),
|
||||||
),
|
),
|
||||||
child: Obx(
|
child: Obx(
|
||||||
() => loginCtrl.isLoginScreen.value
|
() => loginCtrl.isLoginScreen.value
|
||||||
? IconButton(
|
? IconButton(
|
||||||
onPressed: () => loginCtrl.logout(),
|
onPressed: () => loginCtrl.logout(),
|
||||||
icon: Icon(Icons.login, size: 80),
|
icon: const Icon(Icons.login, size: 80),
|
||||||
color: Colors.pink.shade700,
|
color: const Color.fromARGB(
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: IconButton(
|
: IconButton(
|
||||||
onPressed: () => loginCtrl.logout(),
|
onPressed: () => loginCtrl.logout(),
|
||||||
icon: Icon(Icons.app_registration, size: 80),
|
icon: const Icon(
|
||||||
color: Colors.pink.shade700,
|
Icons.app_registration,
|
||||||
|
size: 80,
|
||||||
|
),
|
||||||
|
color: const Color.fromARGB(
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 80),
|
),
|
||||||
|
const SizedBox(height: 80),
|
||||||
Obx(
|
Obx(
|
||||||
() => loginCtrl.isLoginScreen.value
|
() => loginCtrl.isLoginScreen.value
|
||||||
? Text(
|
? Text(
|
||||||
loginCtrl.szHeaderLogin.value,
|
loginCtrl.szHeaderLogin.value,
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
style: Theme.of(
|
||||||
|
context,
|
||||||
|
).textTheme.headlineMedium,
|
||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
loginCtrl.szHeaderSignin.value,
|
loginCtrl.szHeaderSignin.value,
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
style: Theme.of(
|
||||||
|
context,
|
||||||
|
).textTheme.headlineMedium,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
Form(
|
Form(
|
||||||
key: loginCtrl.loginFormKey,
|
key: loginCtrl.loginFormKey,
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -64,32 +108,24 @@ class LoginPage extends GetView<LoginController> {
|
|||||||
? const SizedBox.shrink()
|
? const SizedBox.shrink()
|
||||||
: _nameFormField(loginCtrl),
|
: _nameFormField(loginCtrl),
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_emailFormField(loginCtrl),
|
_emailFormField(loginCtrl),
|
||||||
SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_passwdFormField(loginCtrl),
|
_passwdFormField(loginCtrl),
|
||||||
SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
ElevatedButton(
|
_logOrSignInButton(loginCtrl),
|
||||||
onPressed: () {
|
|
||||||
// Handle login or signin action
|
|
||||||
loginCtrl.logOrSignIn();
|
|
||||||
},
|
|
||||||
child: Obx(
|
|
||||||
() => loginCtrl.isLoginScreen.value
|
|
||||||
? const Text('Login')
|
|
||||||
: const Text('Signin'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Obx(
|
Obx(
|
||||||
() => loginCtrl.isLoginScreen.value
|
() => loginCtrl.isLoginScreen.value
|
||||||
? TextButton(
|
? TextButton(
|
||||||
child: Text(
|
child: Text(
|
||||||
'To Signin',
|
'To Signin',
|
||||||
style: TextStyle(color: Colors.blue.shade500),
|
style: TextStyle(
|
||||||
|
color: Colors.blue.shade800,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
loginCtrl.switchScreen();
|
loginCtrl.switchScreen();
|
||||||
@ -98,7 +134,9 @@ class LoginPage extends GetView<LoginController> {
|
|||||||
: TextButton(
|
: TextButton(
|
||||||
child: Text(
|
child: Text(
|
||||||
'To Login',
|
'To Login',
|
||||||
style: TextStyle(color: Colors.blue.shade500),
|
style: TextStyle(
|
||||||
|
color: Colors.blue.shade800,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
loginCtrl.switchScreen();
|
loginCtrl.switchScreen();
|
||||||
@ -111,6 +149,11 @@ class LoginPage extends GetView<LoginController> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,13 +190,45 @@ class LoginPage extends GetView<LoginController> {
|
|||||||
return InputDecoration(
|
return InputDecoration(
|
||||||
labelText: labelText,
|
labelText: labelText,
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.pink.shade700),
|
borderSide: BorderSide(color: const Color.fromARGB(255, 255, 0, 0)),
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.pink.shade400),
|
borderSide: BorderSide(color: const Color.fromARGB(255, 255, 0, 0)),
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElevatedButton _logOrSignInButton(LoginController loginCtrl) {
|
||||||
|
return ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: const Color.fromARGB(255, 255, 0, 0),
|
||||||
|
minimumSize: const Size(double.infinity, 50),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
// Handle login or signin action
|
||||||
|
loginCtrl.logOrSignIn();
|
||||||
|
},
|
||||||
|
child: Obx(
|
||||||
|
() => loginCtrl.isLoginScreen.value
|
||||||
|
? const Text(
|
||||||
|
'Login',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const Text(
|
||||||
|
'Signin',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user