cpd_job_app/lib/user_state.dart

41 lines
1.3 KiB
Dart
Raw Normal View History

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';
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(
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();
} else if (userSnapshot.hasData) {
2023-06-06 21:29:18 +02:00
print('user is already logged in ');
return JobScreen();
} else if (userSnapshot.hasError) {
2023-06-06 21:29:18 +02:00
return const Scaffold(
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(
child: CircularProgressIndicator(),
));
2023-06-06 21:29:18 +02:00
}
return const Scaffold(
body: Center(
child: Text("Smt went wrong"),
2023-06-06 21:29:18 +02:00
));
},
2023-06-06 21:29:18 +02:00
);
}
}