From 3814f8d08d9eb0ab26aea3b6e39f09490ba3a452 Mon Sep 17 00:00:00 2001 From: nkloos <2020633@stud.hs-mannheim.de> Date: Tue, 6 Jun 2023 21:29:18 +0200 Subject: [PATCH] statetless user state seite, jobs page --- lib/jobs/jobs_screen.dart | 65 +++++++++++++++++++++++++++++++++++++++ lib/main.dart | 3 +- lib/user_state.dart | 44 ++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 lib/jobs/jobs_screen.dart create mode 100644 lib/user_state.dart diff --git a/lib/jobs/jobs_screen.dart b/lib/jobs/jobs_screen.dart new file mode 100644 index 0000000..9e20675 --- /dev/null +++ b/lib/jobs/jobs_screen.dart @@ -0,0 +1,65 @@ +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/material.dart'; + +import '../services/global_variables.dart'; +import '../user_state.dart'; + +class JobScreen extends StatefulWidget { + @override + State createState() => _JobScreenState(); +} + +final _auth = FirebaseAuth.instance; + +class _JobScreenState extends State { + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + + return Scaffold( + body: Stack( + children: [ + Image.network( + signupUrlImage, + fit: BoxFit.cover, + width: double.infinity, + height: double.infinity, + ), + SingleChildScrollView( + child: SizedBox( + height: size.height - 18, // Adjust for bottom overflow + child: Column( + children: [ + AppBar( + backgroundColor: Colors.cyan, + title: const Text('Job Screen'), + actions: [ + IconButton( + icon: Icon(Icons.search), + onPressed: () { + // Action when the search icon is clicked + }, + ), + ], + ), + const SizedBox(height: 80), + ElevatedButton( + onPressed: () { + _auth.signOut(); + Navigator.canPop(context) ? Navigator.pop(context) : null; + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (_) => UserState()), + ); + }, + child: const Text("Log Out"), + ), + ], + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index a7a054a..f5ef1f0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'package:cpd_ss23/login_page/login_screen.dart'; import 'package:cpd_ss23/test.dart'; +import 'package:cpd_ss23/user_state.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:cpd_ss23/firebase_options.dart'; // Importieren Sie die Firebase-Optionen @@ -82,7 +83,7 @@ class MyApp extends StatelessWidget { scaffoldBackgroundColor: Colors.grey, primarySwatch: Colors.blue, ), - home: Login(), + home: UserState(), ); }, ); diff --git a/lib/user_state.dart b/lib/user_state.dart new file mode 100644 index 0000000..25b3410 --- /dev/null +++ b/lib/user_state.dart @@ -0,0 +1,44 @@ +import 'package:cpd_ss23/jobs/jobs_screen.dart'; +import 'package:cpd_ss23/services/global_methods.dart'; +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/material.dart'; + +import 'login_page/login_screen.dart'; + +class UserState extends StatelessWidget {// enthält keine internen Variablen, die sich während der Laufzeit ändern können. + + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream:FirebaseAuth.instance.authStateChanges(),builder: (context, userSnapshot){ + if(userSnapshot.data == null){ + print('user isnt logged in yet'); + return Login(); + } + else if(userSnapshot.hasData){ + print('user is already logged in '); + return JobScreen(); + } + else if(userSnapshot.hasError){ + return const Scaffold( + body: Center( + child:Text("An Error ossured"), + ) + ); + } + else if(userSnapshot.connectionState == ConnectionState.waiting){ + return const Scaffold( + body: Center( + child:CircularProgressIndicator(), + ) + ); + } + return const Scaffold(body:Center( + child:Text( "Smt went wrong"), + )); + }, + + ); + } +}