improvement
parent
4c92525589
commit
daa4a12893
@ -1,217 +1,217 @@
|
|||||||
import 'dart:convert';
|
// import 'dart:convert';
|
||||||
|
//
|
||||||
import 'package:flutter/material.dart';
|
// import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
// import 'package:provider/provider.dart';
|
||||||
import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
|
// import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
|
||||||
import 'package:test_sa/controllers/notification/notification_manger.dart';
|
// import 'package:test_sa/controllers/notification/notification_manger.dart';
|
||||||
import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
|
// import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
|
||||||
import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
|
// import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
|
||||||
import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
// import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
||||||
import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
|
// import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
|
||||||
import 'package:test_sa/extensions/context_extension.dart';
|
// import 'package:test_sa/extensions/context_extension.dart';
|
||||||
import 'package:test_sa/extensions/int_extensions.dart';
|
// import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
import 'package:test_sa/extensions/text_extensions.dart';
|
// import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
// import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
import 'package:test_sa/models/user.dart';
|
// import 'package:test_sa/models/user.dart';
|
||||||
import 'package:test_sa/new_views/app_style/app_color.dart';
|
// import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
import 'package:test_sa/dashboard_latest/widgets/progress_fragment.dart';
|
// import 'package:test_sa/dashboard_latest/widgets/progress_fragment.dart';
|
||||||
import 'package:test_sa/dashboard_latest/widgets/recent_activites_fragment.dart';
|
// import 'package:test_sa/dashboard_latest/widgets/recent_activites_fragment.dart';
|
||||||
import 'package:test_sa/dashboard_latest/widgets/requests_fragment.dart';
|
// import 'package:test_sa/dashboard_latest/widgets/requests_fragment.dart';
|
||||||
import 'package:test_sa/views/pages/user/notifications/notifications_page.dart';
|
// import 'package:test_sa/views/pages/user/notifications/notifications_page.dart';
|
||||||
|
//
|
||||||
class DashboardPage extends StatefulWidget {
|
// class DashboardPage extends StatefulWidget {
|
||||||
final VoidCallback onDrawerPress;
|
// final VoidCallback onDrawerPress; //todo @delete
|
||||||
|
//
|
||||||
const DashboardPage({Key? key,required this.onDrawerPress}) : super(key: key);
|
// const DashboardPage({Key? key,required this.onDrawerPress}) : super(key: key);
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
State<DashboardPage> createState() => _DashboardPageState();
|
// State<DashboardPage> createState() => _DashboardPageState();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
class _DashboardPageState extends State<DashboardPage> {
|
// class _DashboardPageState extends State<DashboardPage> {
|
||||||
int _currentPage = 0;
|
// int _currentPage = 0;
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
void initState() {
|
// void initState() {
|
||||||
super.initState();
|
// super.initState();
|
||||||
getAllRequests();
|
// getAllRequests();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void getAllRequests() {
|
// void getAllRequests() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
Provider.of<AllRequestsProvider>(context, listen: false).getRequests();
|
// Provider.of<AllRequestsProvider>(context, listen: false).getRequests();
|
||||||
Provider.of<NotificationsProvider>(context, listen: false).getSystemNotifications(user: Provider.of<UserProvider>(context, listen: false).user!, resetProvider: true);
|
// Provider.of<NotificationsProvider>(context, listen: false).getSystemNotifications(user: Provider.of<UserProvider>(context, listen: false).user!, resetProvider: true);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
void dispose() {
|
// void dispose() {
|
||||||
super.dispose();
|
// super.dispose();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
bool isFCM = true;
|
// bool isFCM = true;
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
Widget build(BuildContext context) {
|
// Widget build(BuildContext context) {
|
||||||
if (isFCM) {
|
// if (isFCM) {
|
||||||
FirebaseNotificationManger.initialized(context);
|
// FirebaseNotificationManger.initialized(context);
|
||||||
NotificationManger.initialisation((notificationDetails) {
|
// NotificationManger.initialisation((notificationDetails) {
|
||||||
FirebaseNotificationManger.handleMessage(context, json.decode(notificationDetails.payload!));
|
// FirebaseNotificationManger.handleMessage(context, json.decode(notificationDetails.payload!));
|
||||||
}, (id, title, body, payload) async {});
|
// }, (id, title, body, payload) async {});
|
||||||
|
//
|
||||||
isFCM = false;
|
// isFCM = false;
|
||||||
}
|
// }
|
||||||
final User user = Provider.of<UserProvider>(context, listen: false).user!;
|
// final User user = Provider.of<UserProvider>(context, listen: false).user!;
|
||||||
final setting = Provider.of<SettingProvider>(context, listen: false);
|
// final setting = Provider.of<SettingProvider>(context, listen: false);
|
||||||
return Scaffold(
|
// return Scaffold(
|
||||||
appBar: AppBar(
|
// appBar: AppBar(
|
||||||
automaticallyImplyLeading: false,
|
// automaticallyImplyLeading: false,
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
titleSpacing: 0,
|
// titleSpacing: 0,
|
||||||
title: Row(
|
// title: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
// children: [
|
||||||
Consumer<UserProvider>(builder: (context, snapshot, _) {
|
// Consumer<UserProvider>(builder: (context, snapshot, _) {
|
||||||
return CircleAvatar(
|
// return CircleAvatar(
|
||||||
radius: 24,
|
// radius: 24,
|
||||||
backgroundColor: context.isDark ? AppColor.neutral50 : AppColor.neutral40,
|
// backgroundColor: context.isDark ? AppColor.neutral50 : AppColor.neutral40,
|
||||||
child: Padding(
|
// child: Padding(
|
||||||
padding: const EdgeInsets.all(1), // Border radius
|
// padding: const EdgeInsets.all(1), // Border radius
|
||||||
child: ClipOval(
|
// child: ClipOval(
|
||||||
child: snapshot.profileImage != null
|
// child: snapshot.profileImage != null
|
||||||
? Image.file(snapshot.profileImage!)
|
// ? Image.file(snapshot.profileImage!)
|
||||||
: (snapshot.user?.profilePhotoName?.isNotEmpty ?? false)
|
// : (snapshot.user?.profilePhotoName?.isNotEmpty ?? false)
|
||||||
? Image.network(snapshot.user!.profilePhotoName!)
|
// ? Image.network(snapshot.user!.profilePhotoName!)
|
||||||
: const Icon(Icons.person, size: 24, color: Colors.white),
|
// : const Icon(Icons.person, size: 24, color: Colors.white),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
}).onPress(widget.onDrawerPress),
|
// }).onPress(widget.onDrawerPress),
|
||||||
const Spacer(),
|
// const Spacer(),
|
||||||
Container(
|
// Container(
|
||||||
padding: const EdgeInsets.fromLTRB(12, 6, 6, 6),
|
// padding: const EdgeInsets.fromLTRB(12, 6, 6, 6),
|
||||||
decoration: BoxDecoration(
|
// decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(8),
|
// borderRadius: BorderRadius.circular(8),
|
||||||
color: AppColor.background(context),
|
// color: AppColor.background(context),
|
||||||
boxShadow: const [
|
// boxShadow: const [
|
||||||
BoxShadow(
|
// BoxShadow(
|
||||||
color: Color(0x07000000),
|
// color: Color(0x07000000),
|
||||||
blurRadius: 14,
|
// blurRadius: 14,
|
||||||
offset: Offset(0, 0),
|
// offset: Offset(0, 0),
|
||||||
spreadRadius: 0,
|
// spreadRadius: 0,
|
||||||
)
|
// )
|
||||||
],
|
// ],
|
||||||
),
|
// ),
|
||||||
child: DropdownButton<AssetGroup>(
|
// child: DropdownButton<AssetGroup>(
|
||||||
value: setting.assetGroup,
|
// value: setting.assetGroup,
|
||||||
//iconSize: 24,
|
// //iconSize: 24,
|
||||||
isDense: true,
|
// isDense: true,
|
||||||
icon: const Icon(Icons.keyboard_arrow_down),
|
// icon: const Icon(Icons.keyboard_arrow_down),
|
||||||
elevation: 8,
|
// elevation: 8,
|
||||||
// dropdownColor: Colors.amber,
|
// // dropdownColor: Colors.amber,
|
||||||
borderRadius: BorderRadius.circular(8),
|
// borderRadius: BorderRadius.circular(8),
|
||||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
// style: TextStyle(color: Theme.of(context).primaryColor),
|
||||||
underline: const SizedBox.shrink(),
|
// underline: const SizedBox.shrink(),
|
||||||
onChanged: (newValue) {
|
// onChanged: (newValue) {
|
||||||
if (setting.assetGroup != newValue) {
|
// if (setting.assetGroup != newValue) {
|
||||||
Provider.of<SettingProvider>(context, listen: false).setAssetGroup(newValue);
|
// Provider.of<SettingProvider>(context, listen: false).setAssetGroup(newValue);
|
||||||
setState(() {});
|
// setState(() {});
|
||||||
getAllRequests();
|
// getAllRequests();
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
items: user.assetGroups!.map<DropdownMenuItem<AssetGroup>>((value) {
|
// items: user.assetGroups!.map<DropdownMenuItem<AssetGroup>>((value) {
|
||||||
return DropdownMenuItem<AssetGroup>(
|
// return DropdownMenuItem<AssetGroup>(
|
||||||
value: value,
|
// value: value,
|
||||||
child: Text(
|
// child: Text(
|
||||||
value.name ?? "",
|
// value.name ?? "",
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
// style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
}).toList(),
|
// }).toList(),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
16.width,
|
// 16.width,
|
||||||
Stack(
|
// Stack(
|
||||||
alignment: Alignment.topRight,
|
// alignment: Alignment.topRight,
|
||||||
children: [
|
// children: [
|
||||||
Icon(Icons.notifications, color: context.isDark ? AppColor.neutral30 : AppColor.neutral20, size: 30).paddingOnly(top: 6, end: 0),
|
// Icon(Icons.notifications, color: context.isDark ? AppColor.neutral30 : AppColor.neutral20, size: 30).paddingOnly(top: 6, end: 0),
|
||||||
// todo @sikander will add count for unread notifications
|
// // todo @sikander will add count for unread notifications
|
||||||
// Positioned(
|
// // Positioned(
|
||||||
// top: 0,
|
// // top: 0,
|
||||||
// right: 0,
|
// // right: 0,
|
||||||
// child: Container(
|
// // child: Container(
|
||||||
// padding: const EdgeInsets.all(4),
|
// // padding: const EdgeInsets.all(4),
|
||||||
// decoration: const ShapeDecoration(
|
// // decoration: const ShapeDecoration(
|
||||||
// color: Color(0xFFD02127),
|
// // color: Color(0xFFD02127),
|
||||||
// shape: CircleBorder(),
|
// // shape: CircleBorder(),
|
||||||
// ),
|
// // ),
|
||||||
// child: Text("", style: AppTextStyles.bodyText),
|
// // child: Text("", style: AppTextStyles.bodyText),
|
||||||
// ),
|
// // ),
|
||||||
// )
|
// // )
|
||||||
],
|
// ],
|
||||||
).onPress(() {
|
// ).onPress(() {
|
||||||
Navigator.of(context).pushNamed(NotificationsPage.id);
|
// Navigator.of(context).pushNamed(NotificationsPage.id);
|
||||||
}),
|
// }),
|
||||||
],
|
// ],
|
||||||
).paddingOnly(start: 16, end: 16),
|
// ).paddingOnly(start: 16, end: 16),
|
||||||
),
|
// ),
|
||||||
body: Column(
|
// body: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
// children: [
|
||||||
Column(
|
// Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
// mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
// children: [
|
||||||
Text(
|
// Text(
|
||||||
context.translation.welcome,
|
// context.translation.welcome,
|
||||||
style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
// style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
||||||
),
|
// ),
|
||||||
Text(
|
// Text(
|
||||||
user.username ?? "",
|
// user.username ?? "",
|
||||||
style: AppTextStyles.heading2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50, fontWeight: FontWeight.w600),
|
// style: AppTextStyles.heading2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50, fontWeight: FontWeight.w600),
|
||||||
),
|
// ),
|
||||||
24.height,
|
// 24.height,
|
||||||
Row(
|
// Row(
|
||||||
children: [
|
// children: [
|
||||||
indicatorView(0),
|
// indicatorView(0),
|
||||||
3.width,
|
// 3.width,
|
||||||
indicatorView(1),
|
// indicatorView(1),
|
||||||
3.width,
|
// 3.width,
|
||||||
indicatorView(2),
|
// indicatorView(2),
|
||||||
10.width,
|
// 10.width,
|
||||||
"0${_currentPage + 1}/03".tinyFont(context).custom(fontWeight: FontWeight.w500, color: context.isDark ? AppColor.neutral30 : AppColor.neutral60),
|
// "0${_currentPage + 1}/03".tinyFont(context).custom(fontWeight: FontWeight.w500, color: context.isDark ? AppColor.neutral30 : AppColor.neutral60),
|
||||||
],
|
// ],
|
||||||
),
|
// ),
|
||||||
],
|
// ],
|
||||||
).paddingOnly(start: 16, end: 16, top: 8, bottom: 8),
|
// ).paddingOnly(start: 16, end: 16, top: 8, bottom: 8),
|
||||||
PageView(
|
// PageView(
|
||||||
onPageChanged: (index) => setState(() => _currentPage = index),
|
// onPageChanged: (index) => setState(() => _currentPage = index),
|
||||||
children: [
|
// children: [
|
||||||
const RequestsFragment(),
|
// const RequestsFragment(),
|
||||||
ProgressFragment(),
|
// ProgressFragment(),
|
||||||
const RecentActivitiesFragment(),
|
// const RecentActivitiesFragment(),
|
||||||
],
|
// ],
|
||||||
).expanded,
|
// ).expanded,
|
||||||
],
|
// ],
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Widget indicatorView(int index) {
|
// Widget indicatorView(int index) {
|
||||||
bool isActive = _currentPage == index;
|
// bool isActive = _currentPage == index;
|
||||||
|
//
|
||||||
return AnimatedContainer(
|
// return AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 250),
|
// duration: const Duration(milliseconds: 250),
|
||||||
width: (isActive ? 30 : 12).toScreenWidth,
|
// width: (isActive ? 30 : 12).toScreenWidth,
|
||||||
height: 9.toScreenHeight,
|
// height: 9.toScreenHeight,
|
||||||
decoration: BoxDecoration(
|
// decoration: BoxDecoration(
|
||||||
color: isActive
|
// color: isActive
|
||||||
? AppColor.greenStatus(context)
|
// ? AppColor.greenStatus(context)
|
||||||
: context.isDark
|
// : context.isDark
|
||||||
? AppColor.neutral20
|
// ? AppColor.neutral20
|
||||||
: AppColor.neutral40,
|
// : AppColor.neutral40,
|
||||||
borderRadius: BorderRadius.circular(8)),
|
// borderRadius: BorderRadius.circular(8)),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
Loading…
Reference in New Issue