statetless user state seite, jobs page
parent
51ebeea554
commit
3814f8d08d
|
@ -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<JobScreen> createState() => _JobScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
final _auth = FirebaseAuth.instance;
|
||||||
|
|
||||||
|
class _JobScreenState extends State<JobScreen> {
|
||||||
|
@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"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:cpd_ss23/login_page/login_screen.dart';
|
import 'package:cpd_ss23/login_page/login_screen.dart';
|
||||||
import 'package:cpd_ss23/test.dart';
|
import 'package:cpd_ss23/test.dart';
|
||||||
|
import 'package:cpd_ss23/user_state.dart';
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:cpd_ss23/firebase_options.dart'; // Importieren Sie die Firebase-Optionen
|
import 'package:cpd_ss23/firebase_options.dart'; // Importieren Sie die Firebase-Optionen
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ class MyApp extends StatelessWidget {
|
||||||
scaffoldBackgroundColor: Colors.grey,
|
scaffoldBackgroundColor: Colors.grey,
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
home: Login(),
|
home: UserState(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -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"),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue