cpd_job_app/lib/Widgets/bottom_nav_bar.dart

109 lines
3.7 KiB
Dart

import 'package:cpd_ss23/Search/profile_company.dart';
import 'package:cpd_ss23/Search/search_companies.dart';
import 'package:cpd_ss23/jobs/upload_job.dart';
import 'package:cpd_ss23/user_state.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import '../jobs/jobs_screen.dart';
class BottomNavigationBarForApp extends StatelessWidget {
int indexNum = 0;
BottomNavigationBarForApp({required this.indexNum});
void _logout(context) {
final FirebaseAuth _auth = FirebaseAuth.instance;
showDialog(
context: context,
builder: (context){
return AlertDialog(
backgroundColor: Colors.black54,
title: const Row(
children: [
Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.logout,
color: Colors.white,
size: 36
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Sign Out",
style: TextStyle(color: Colors.white, fontSize: 28),
),
),
],
),
content: const Text(
"Do you want to Log Out?",
style: TextStyle(
color: Colors.white, fontSize: 20
),
),
actions: [
TextButton(
onPressed: (){
Navigator.canPop(context) ? Navigator.pop(context) : null;
},
child: const Text("No", style: TextStyle(color: Colors.green, fontSize: 18),),
),
TextButton(
onPressed: (){
_auth.signOut();
Navigator.canPop(context) ? Navigator.pop(context) : null;
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => UserState()));
},
child: const Text("Yes", style: TextStyle(color: Colors.green, fontSize: 18),),
)
],
);
}
);
}
@override
Widget build(BuildContext context) {
return CurvedNavigationBar(
color: Colors.cyan,
backgroundColor: Colors.black,
buttonBackgroundColor: Colors.white,
height: 50,
index: indexNum,
items: const [
Icon(Icons.list, size: 19, color: Colors.black,),
Icon(Icons.search, size: 19, color: Colors.black,),
Icon(Icons.add, size: 19, color: Colors.black,),
Icon(Icons.person_pin, size: 19, color: Colors.black,),
Icon(Icons.exit_to_app, size: 19, color: Colors.black,),
],
animationDuration: const Duration(
milliseconds: 300,
),
animationCurve: Curves.bounceInOut,
onTap: (index){
if(index == 0){
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => JobScreen()));
} else if (index == 1){
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => AllWorkersScreen()));
} else if (index == 2){
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => UploadJobNow()));
} else if (index == 3){
final FirebaseAuth _auth=FirebaseAuth.instance;
final User? user = _auth.currentUser;
final String uid = user!.uid;
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => ProfileScreen(userId: uid)));
}
else if (index == 4){
_logout(context);
}
},
);
}
}