Application/medcify/lib/pages/main/home/home_page.dart

145 lines
5.5 KiB
Dart
Raw Normal View History

2022-09-26 06:33:52 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:medcify/components/loader.dart';
import 'package:medcify/navigation/navigation.dart';
import 'package:medcify/pages/main/home/banner_card.dart';
import 'package:medcify/pages/main/home/drawer_widget.dart';
import 'package:medcify/pages/main/home/home_bloc.dart';
import 'package:medcify/pages/main/home/whatsapp_share.dart';
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider<HomeCubit>(
create: (context) => HomeCubit(),
child: HomeWidget(),
);
}
}
class HomeWidget extends StatelessWidget {
late HomeCubit homeCubit;
Widget overview(String title, dynamic count, Color color, Color lightColor){
return Container(
decoration: BoxDecoration(
color: lightColor,
borderRadius: BorderRadius.circular(4),
border: Border.all(color:color)
),
padding: const EdgeInsets.symmetric(horizontal: 8,vertical: 8),
alignment: Alignment.center,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(title,style: TextStyle(color: color,fontWeight: FontWeight.w600,fontSize: 18),),
const SizedBox(height: 8,),
Text("$count",style: TextStyle(color: color, fontSize: 30, fontWeight: FontWeight.w600),)
],
),
);
}
@override
Widget build(BuildContext context) {
homeCubit = BlocProvider.of<HomeCubit>(context);
homeCubit.fetchHomeData();
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0.25,
backgroundColor: Colors.white,
title: const Text("Home",style: TextStyle(color: Colors.black,fontSize: 17),),
iconTheme: const IconThemeData(
color: Colors.black
),
actions: [
BlocBuilder<HomeCubit, HomeState>(
builder: (context, state){
return SizedBox(
height: 50,
width: 50,
child: Stack(
children: [
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: IconButton(
onPressed: (){
Navigation.instance.navigate("/notification");
},
icon: const Icon(Icons.notifications),
),
),
Visibility(
visible: state is HomeSuccess && homeCubit.notificationCount > 0,
child: Align(
alignment: Alignment.topRight,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.red
),
height: 18,
width: 18,
margin: const EdgeInsets.only(right: 12,top: 4),
alignment: Alignment.center,
child: Text((homeCubit.notificationCount > 10) ? "10+" : "${homeCubit.notificationCount}",style: const TextStyle(color: Colors.white, fontWeight: FontWeight.w600, fontSize: 8),),
),
),
)
],
),
);
}
)
],
),
drawer: DrawerWidget(),
body: BlocBuilder<HomeCubit, HomeState>(
builder: (context, state){
if(state is HomeLoading){
return const Loader();
}else{
return SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 8,),
BannerCard(banners: homeCubit.banners),
const SizedBox(height: 18,),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Text("OverView",style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600,fontSize: 17),),
),
const SizedBox(height: 16,),
GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 1.25
),
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.symmetric(horizontal: 16),
children: [
overview("Orders", homeCubit.ordersCount, Colors.blue, Colors.blue.shade50),
overview("Sales", homeCubit.salesCount, Colors.purple, Colors.purple.shade50),
overview("Visitors", homeCubit.visitorsCount, Colors.red, Colors.red.shade50),
],
),
const SizedBox(height: 20,),
WhatsappShare(homeCubit.url,homeCubit.storeName),
const SizedBox(height: 16,),
],
),
);
}
},
),
);
}
}