2023-06-06 21:29:18 +02:00
|
|
|
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';
|
|
|
|
|
2023-06-23 12:12:02 +02:00
|
|
|
class UserState extends StatelessWidget {
|
|
|
|
// enthält keine internen Variablen, die sich während der Laufzeit ändern können.
|
2023-06-06 21:29:18 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return StreamBuilder(
|
2023-06-23 12:12:02 +02:00
|
|
|
stream: FirebaseAuth.instance.authStateChanges(),
|
|
|
|
builder: (context, userSnapshot) {
|
|
|
|
if (userSnapshot.data == null) {
|
2023-06-06 21:29:18 +02:00
|
|
|
print('user isnt logged in yet');
|
|
|
|
return Login();
|
2023-06-23 12:12:02 +02:00
|
|
|
} else if (userSnapshot.hasData) {
|
2023-06-06 21:29:18 +02:00
|
|
|
print('user is already logged in ');
|
|
|
|
return JobScreen();
|
2023-06-23 12:12:02 +02:00
|
|
|
} else if (userSnapshot.hasError) {
|
2023-06-06 21:29:18 +02:00
|
|
|
return const Scaffold(
|
2023-06-23 12:12:02 +02:00
|
|
|
body: Center(
|
|
|
|
child: Text("An Error ossured"),
|
|
|
|
));
|
|
|
|
} else if (userSnapshot.connectionState == ConnectionState.waiting) {
|
2023-06-06 21:29:18 +02:00
|
|
|
return const Scaffold(
|
|
|
|
body: Center(
|
2023-06-23 12:12:02 +02:00
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
));
|
2023-06-06 21:29:18 +02:00
|
|
|
}
|
2023-06-23 12:12:02 +02:00
|
|
|
return const Scaffold(
|
|
|
|
body: Center(
|
|
|
|
child: Text("Smt went wrong"),
|
2023-06-06 21:29:18 +02:00
|
|
|
));
|
2023-06-23 12:12:02 +02:00
|
|
|
},
|
2023-06-06 21:29:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|