sc-android-app/lib/screens/home_screen.dart
2024-09-06 12:40:46 +05:30

292 lines
11 KiB
Dart

import 'package:cheminova/notification_services.dart';
import 'package:cheminova/provider/home_provider.dart';
import 'package:cheminova/screens/Update_inventorytask_screen.dart';
import 'package:cheminova/screens/calendar_screen.dart';
import 'package:cheminova/screens/daily_tasks_screen.dart';
import 'package:cheminova/screens/mark_attendence_screen.dart';
import 'package:cheminova/screens/notification_screen.dart';
import 'package:cheminova/screens/product_purchase_data.dart';
import 'package:cheminova/screens/products_manual_screen.dart';
import 'package:cheminova/screens/rejected_application_screen.dart';
import 'package:cheminova/screens/sales_task_screen.dart';
import 'package:cheminova/screens/select_taskkyc_screen.dart';
import 'package:cheminova/widgets/common_app_bar.dart';
import 'package:cheminova/widgets/common_background.dart';
import 'package:cheminova/widgets/common_drawer.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
NotificationServices notificationServices = NotificationServices();
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Provider.of<HomeProvider>(context, listen: false).getProfile();
notificationServices.requestNotificationPermission();
notificationServices.getDeviceToken().then((value) {
if (kDebugMode) {
print('Device Token: $value');
}
});
});
}
@override
Widget build(BuildContext context) {
return CommonBackground(
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: CommonAppBar(
title: Row(children: [
const SizedBox(width: 10),
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const Text('Welcome',
style: TextStyle(
color: Colors.black87,
fontSize: 14,
fontWeight: FontWeight.w400)),
Consumer<HomeProvider>(
builder: (context, value, child) =>
(value.profileResponse == null ||
value.profileResponse!.myData == null ||
value.profileResponse!.myData!.name == null)
? const SizedBox()
: Text(value.profileResponse!.myData!.name ?? '',
style: const TextStyle(
color: Colors.black87, fontSize: 20)))
])
]),
backgroundColor: Colors.transparent,
elevation: 0,
),
drawer: const CommonDrawer(),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: LayoutBuilder(
builder: (context, constraints) {
double screenWidth = constraints.maxWidth;
double buttonWidth = screenWidth / 2 - 18; // Adjust button width
return ListView(
children: [
_buildCustomCard(
'Mark Attendance',
'Mark Attendance / On Leave',
screenWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MarkAttendanceScreen(),
),
);
},
),
const SizedBox(height: 5),
_buildCustomCard(
'Daily Tasks',
'Dashboard',
screenWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DailyTasksScreen(),
),
);
},
),
const SizedBox(height: 5),
Row(
children: [
Expanded(
child: _buildCustomCard(
'Update\nSales data',
'Quickly display Sales',
buttonWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SalesTaskScreen()
),
);
},
),
),
const SizedBox(width: 12),
Expanded(
child: _buildCustomCard(
'Update Inventory Data',
'Quickly Inventory Data',
buttonWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const UpdateInventoryTaskScreen(),
),
);
},
),
),
],
),
const SizedBox(height: 5),
Row(
children: [
Expanded(
child: _buildCustomCard(
'Notifications',
'Tasks & Alerts\n\n',
buttonWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const NotificationScreen(),
),
);
},
),
),
const SizedBox(width: 12),
Expanded(
child: _buildCustomCard(
'Product\nPurchase Data Visibility',
'',
buttonWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const ProductPurchaseData(),
),
);
},
),
),
],
),
const SizedBox(height: 5),
_buildCustomCard(
'Collect \nKYC Data',
'Scan and upload KYC Documents',
screenWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SelectTaskkycScreen(),
),
);
},
),
const SizedBox(height: 5),
_buildCustomCard(
'Rejected Applications',
'Re-upload Rejected Documents',
screenWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const RejectedApplicationScreen(),
),
);
},
),
const SizedBox(height: 5),
Row(
children: [
Expanded(
child: _buildCustomCard(
'Calendar',
'Appointments & Deadlines',
buttonWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const CalendarScreen(),
),
);
},
),
),
const SizedBox(width: 12),
Expanded(
child: _buildCustomCard(
'Products Manual',
'Details of products',
buttonWidth,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const ProductsManualScreen(),
),
);
},
),
),
],
),
],
);
},
),
),
),
),
);
}
Widget _buildCustomCard(String title, String subtitle, double width,
{void Function()? onTap}) {
return Container(
width: width,
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.indigo,
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(10),
),
child: ListTile(
title: Text(
title,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w800,
fontSize: 18,
fontFamily: 'Anek'),
),
subtitle: subtitle.isNotEmpty
? Text(
subtitle,
style: const TextStyle(color: Colors.white70, fontSize: 13),
)
: null,
onTap: onTap,
),
);
}
}