Application/medcify/lib/pages/main/main_page.dart

88 lines
2.6 KiB
Dart
Raw Normal View History

2022-09-26 06:33:52 +00:00
import 'package:flutter/material.dart';
import 'package:medcify/pages/main/home/home_page.dart';
import 'package:medcify/pages/main/orders/orders_page.dart';
import 'package:medcify/pages/main/products/products_page.dart';
import 'package:medcify/pages/main/settings/settings_page.dart';
import 'package:medcify/storage/storage.dart';
import '../../constants.dart';
import '../../network/api_provider.dart';
import 'firebase_push_notification.dart';
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int currentIndex = 0;
Widget bodyWidget(){
if(currentIndex == 0){
return const HomePage();
}else if(currentIndex == 1){
return const OrdersPage();
}else if(currentIndex == 2){
return const ProductsPage();
}
return const SettingsPage();
}
Future<void> initializeFirebase() async{
String token = await FirebaseX.instance.firebaseMessaging.getToken() ?? "";
await ApiProvider.instance.updateFcm(token);
await FirebaseX.instance.onFirebaseMessagingInitialize();
FirebaseX.instance.onRegisterFirebaseNotificationTopics(["general"]);
}
@override
initState(){
Storage.instance.fetchRazorPayData();
initializeFirebase();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBarTheme(
data: const BottomNavigationBarThemeData(
backgroundColor: Colors.white
),
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: currentIndex,
selectedItemColor: Constants.primaryColor,
unselectedItemColor: const Color(0xff8F9BB3),
onTap: (int index){
setState(() {
currentIndex = index;
});
},
items: const [
BottomNavigationBarItem(
icon: ImageIcon(AssetImage("assets/images/home.png")),
label: "Home"
),
BottomNavigationBarItem(
icon: ImageIcon(AssetImage("assets/images/orders.png")),
label: "Orders"
),
BottomNavigationBarItem(
icon: ImageIcon(AssetImage("assets/images/medicine.png")),
label: "Products"
),
BottomNavigationBarItem(
icon: ImageIcon(AssetImage("assets/images/setting.png")),
label: "Settings"
),
],
),
),
body: bodyWidget(),
);
}
}