import 'package:badges/badges.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:the_kosmo_club/providers/plans.dart';
import 'package:the_kosmo_club/providers/user.dart';
import 'package:the_kosmo_club/services/database.dart';
import 'package:the_kosmo_club/views/chatrooms.dart';
import 'package:provider/provider.dart';
import 'package:the_kosmo_club/views/eliminated.dart';
import 'package:the_kosmo_club/views/home.dart';
import 'package:the_kosmo_club/views/info.dart';
import 'package:the_kosmo_club/views/profile.dart';
class BottomNav extends StatefulWidget {
final int currentIndex;
final String userEmail;
BottomNav({this.currentIndex = 0, @required this.userEmail});
@override
_BottomNavState createState() => _BottomNavState(currentIndex: currentIndex);
}
class _BottomNavState extends State<BottomNav> {
int currentIndex;
_BottomNavState({this.currentIndex});
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
final tabs = [
HomePage(),
ChatRoom(),
ProfilePage(),
ElemenatedActivitiesPage(),
InfoPage()
];
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (ctx) => Plans(),
),
ChangeNotifierProvider(
create: (ctx) => Usser(),
),
],
child: Scaffold(
bottomNavigationBar: BottomNavigationBar(
iconSize: 40,
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.black,
selectedLabelStyle: TextStyle(fontSize: 0),
unselectedLabelStyle: TextStyle(fontSize: 0),
selectedItemColor: Colors.white,
unselectedItemColor: Colors.grey,
currentIndex: currentIndex,
items: [
BottomNavigationBarItem(
label: '',
icon: Icon(
MaterialIcons.home,
),
),
BottomNavigationBarItem(
label: '',
icon: StreamBuilder<QuerySnapshot>(
stream: DatabaseMethods().unReadMsg(widget.userEmail),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Icon(Icons.message);
} else if (snapshot.connectionState == ConnectionState.done) {
return snapshot.data.docs.length > 0
? Badge(
position: const BadgePosition(
top: -5,
start: -5,
),
child: const Icon(Icons.message),
)
: const Icon(Icons.message);
} else if (snapshot.hasError) {
return const Icon(Icons.message);
} else {
return snapshot.data.docs.length > 0
? Badge(
position: const BadgePosition(
top: -5,
start: -5,
),
child: const Icon(Icons.message),
)
: const Icon(Icons.message);
}
},
),
),
BottomNavigationBarItem(
label: '',
icon: Icon(
Icons.favorite,
),
),
BottomNavigationBarItem(
label: '',
icon: Icon(
Icons.add_circle_sharp,
),
),
BottomNavigationBarItem(
label: '',
icon: Icon(
Icons.info_rounded,
),
),
],
onTap: (index) {
setState(() {
currentIndex = index;
});
},
),
body: IndexedStack(
index: currentIndex,
children: tabs,
),
),
);
}
}