You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

689 lines
30 KiB

import 'dart:convert';
import 'dart:io';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:supplier_new/common/settings.dart';
import '../login/login.dart';
class DashboardScreen extends StatefulWidget {
const DashboardScreen({super.key});
@override
State<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
int _currentIndex = 0;
final ImagePicker _picker = ImagePicker();
final storage = FlutterSecureStorage(
aOptions: AndroidOptions(
resetOnError: true,
encryptedSharedPreferences: true,
),
);
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
// Define a list of widgets for each screen
final List<Widget> _screens = [
HomeScreen(),
HomeScreen(),
HomeScreen(),
HomeScreen(),
HomeScreen(),
];
// List of bottom navigation bar items
final List<BottomNavigationBarItem> _bottomNavItems = [
BottomNavigationBarItem(
icon:Padding(
padding: EdgeInsets.fromLTRB(0,5,0,0), // Adjust height to control spacing
child:ImageIcon(AssetImage('images/homeBottomIcon.png')),),
// Replace with your image path
label: "Home",
),
BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.fromLTRB(0,5,0,0), // Adjust height to control spacing
child: ImageIcon(AssetImage('images/ordersBottomIcon.png')),
),
label: "Orders",
),
BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.fromLTRB(0,5,0,0), // Adjust height to control spacing
child: ImageIcon(AssetImage('images/plansBottomIcon.png')),
), // Replace with your image path
label: "Plans",
),
BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.fromLTRB(0,5,0,0), // Adjust height to control spacing
child:ImageIcon(AssetImage('images/resourcesBottomIcon.png')),),
// Replace with your image path
label: "Resources",
),
BottomNavigationBarItem(
icon:Padding(
padding: EdgeInsets.fromLTRB(0,5,0,0), // Adjust height to control spacing
child:ImageIcon(AssetImage('images/financialsBottomIcon.png')),),
// Replace with your image path
label: "Financials",
),
];
void _onItemTapped(int index) {
setState(() {
_currentIndex = index;
});
}
Future pickImageFromGallery() async {
try {
final image = await _picker.pickImage(source: ImageSource.gallery);
if (image == null) return;
final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
bool isOnline = await AppSettings.internetConnectivity();
if(isOnline) {
var res = await AppSettings.uploadrofileImageHTTPNew(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
AppSettings.profilePictureUrl = jsonDecode(res)['picture'];
});
AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING');
}
else{
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast('Please check interent');
}
} on PlatformException catch (e) {
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast('Failed to pick image: $e');
}
}
Future takeImageFromCamera() async {
try {
final image = await _picker.pickImage(source: ImageSource.camera);
if (image == null) return;
final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
bool isOnline = await AppSettings.internetConnectivity();
if(isOnline){
var res = await AppSettings.uploadrofileImageHTTPNew(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
AppSettings.profilePictureUrl = jsonDecode(res)['picture'];
});
AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING');
}
else{
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast('Please check interent');
}
} on PlatformException catch (e) {
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast('Failed to pick image: $e');
}
}
showLogoutAlertDialog(context) {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return AlertDialog(
backgroundColor: Color(0XFFFFFFFF),// Set your desired background color
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12), // Optional: Rounded corners
),
title: Center(child: Text('Logout?',style:fontTextStyle(16,Color(0XFF101214),FontWeight.w700)),),
actions: <Widget>[
Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(child: GestureDetector(
onTap: (){
Navigator.of(context).pop();
},
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Color(0XFFFFFFFF),
border: Border.all(
width: 1,
color: Color(0XFF1D7AFC)),
borderRadius: BorderRadius.circular(
12,
)),
alignment: Alignment.center,
child: Visibility(
visible: true,
child: Padding(
padding: EdgeInsets.fromLTRB(16,12,16,12),
child: Text(
'Cancel',
style: fontTextStyle(
12,
Color(0XFF1D7AFC),
FontWeight.w600)),
),
),
),
),),
SizedBox(width:MediaQuery.of(context).size.width * .016,),
Expanded(child: GestureDetector(
onTap: ()async{
await storage.deleteAll();
await Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => Login()),
(Route<dynamic> route) => false,
);
},
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Color(0XFFE2483D),
border: Border.all(
width: 1,
color: Color(0XFFE2483D)),
borderRadius: BorderRadius.circular(
12,
)),
alignment: Alignment.center,
child: Visibility(
visible: true,
child: Padding(
padding: EdgeInsets.fromLTRB(16,12,16,12),
child: Text(
'Logout',
style: fontTextStyle(
12,
Color(0XFFFFFFFF),
FontWeight.w600)),
),
),
)
),)
],
),
),
]);
});
});
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (_scaffoldKey.currentState?.isDrawerOpen ?? false) {
// If the drawer is open, close it
_scaffoldKey.currentState?.openEndDrawer();
return false; // Prevent the default back action (exit the app)
}
else if (_currentIndex == 2) {
final shouldPop = await showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
backgroundColor: Color(0XFFFFFFFF),// Set your desired background color
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12), // Optional: Rounded corners
),
title: Center(child: Text('Do you want to exit app?',style:fontTextStyle(16,Color(0XFF101214),FontWeight.w700)),),
actionsAlignment: MainAxisAlignment.spaceBetween,
actions: [
Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(child: GestureDetector(
onTap: (){
Navigator.of(context).pop(false);
},
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Color(0XFFFFFFFF),
border: Border.all(
width: 1,
color: Color(0XFF1D7AFC)),
borderRadius: BorderRadius.circular(
12,
)),
alignment: Alignment.center,
child: Visibility(
visible: true,
child: Padding(
padding: EdgeInsets.fromLTRB(16,12,16,12),
child: Text(
'Cancel',
style: fontTextStyle(
12,
Color(0XFF1D7AFC),
FontWeight.w600)),
),
),
),
),),
SizedBox(width:MediaQuery.of(context).size.width * .016,),
Expanded(child: GestureDetector(
onTap: ()async{
SystemNavigator.pop();
},
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Color(0XFF1D7AFC),
border: Border.all(
width: 1,
color: Color(0XFF1D7AFC)),
borderRadius: BorderRadius.circular(
12,
)),
alignment: Alignment.center,
child: Visibility(
visible: true,
child: Padding(
padding: EdgeInsets.fromLTRB(16,12,16,12),
child: Text(
'Confirm',
style: fontTextStyle(
12,
Color(0XFFFFFFFF),
FontWeight.w600)),
),
),
)
),)
],
),
),
],
);
},
);
return shouldPop!;
}
else {
setState(() {
_currentIndex = 2;
});
return false;
}
},
child: Scaffold(
key: _scaffoldKey,
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
scrolledUnderElevation: 0,
title: Text(_currentIndex==2?'Aquinto':_currentIndex==0?'History':_currentIndex==1?'Usage':_currentIndex==3?'Water Levels':'Resources',style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w500),),
iconTheme: IconThemeData(color: Color(0XFF2A2A2A)),
actions: [
Row(
children: [
Padding(padding: EdgeInsets.fromLTRB(10,10,0,10),
child: IconButton(
icon: Image(
image: AssetImage('images/calendar_appbar.png')
),
onPressed: (){
},
),
),
Padding(padding: EdgeInsets.fromLTRB(0,10,10,10),
child: IconButton(
icon: Image.asset(
'images/notification_appbar.png', // Example URL image
),
onPressed: (){
},
),
)
],
)
],
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
_scaffoldKey.currentState?.openDrawer();
},
),
),
drawer: Drawer(
width: MediaQuery.of(context).size.width,
backgroundColor: Colors.white,
child: Padding(
padding: EdgeInsets.all(8),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(height:MediaQuery.of(context).size.height * .05,),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
/* GestureDetector(
onTap: (){
Navigator.of(context).pop(true);
},
child: Image.asset('images/appbar_backbutton.png',height: 25,width: 25,color: Color(0XFF2A2A2A),),
),*/
SizedBox(width:MediaQuery.of(context).size.width * .04,),
Text(
'Menu',
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w500),
),
],
),
SizedBox(height:MediaQuery.of(context).size.height * .016,),
Padding( padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
/*CircleAvatar(
radius: 50, // Adjust the size of the circle
backgroundColor: Colors.grey[200],
backgroundImage:AppSettings.profilePictureUrl !=
'' &&
AppSettings.profilePictureUrl !=
'null'?NetworkImage(AppSettings
.profilePictureUrl) as ImageProvider: AssetImage('images/profile_pic.png',), // Your profile image
),*/
AppSettings.loginType.toString().toLowerCase()=='user'?
GestureDetector(
onTap: () {
/*Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new ImageZoomPage(
imageName: 'Profile',
imageDetails: AppSettings.profilePictureUrl)));*/
},
child: Stack(
alignment: Alignment.center, // Centers the stack's children
children: [
// CircleAvatar background
ClipOval(
child: Container(
height: 100, // Ensure the container's height is the same as the profile image
width: 100,
decoration: BoxDecoration(
color: Colors.transparent,
shape: BoxShape.circle, // Makes the container circular
image: DecorationImage(
image: (AppSettings.profilePictureUrl !=
'' &&
AppSettings.profilePictureUrl !=
'null')
? NetworkImage(AppSettings.profilePictureUrl)
as ImageProvider
: AssetImage(
"images/profile_pic.png"), // picked file
fit: BoxFit.cover)),
),
),
// Positioned image on top of CircleAvatar
Positioned(
bottom: 0, // Adjust position as needed
right: 0, // Adjust position as needed
child: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 4,
offset: Offset(0, 2), // Shadow to make the edit icon pop
),
],
shape: BoxShape.circle,
color: Colors.white, // Background for the overlay
),
child: GestureDetector(
onTap: (){
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCamera();
Navigator.pop(context);
},
),
SizedBox(
width: MediaQuery.of(context)
.size
.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGallery();
Navigator.pop(context);
},
),
],
),
),
);
});
},
child: Image.asset(
'images/edit_profile.png', // Ensure the image path is correct
fit: BoxFit.cover,
),
),
),
),
],
),
):ClipOval(
child: Container(
height: 100, // Ensure the container's height is the same as the profile image
width: 100,
decoration: BoxDecoration(
color: Colors.transparent,
shape: BoxShape.circle, // Makes the container circular
image: DecorationImage(
image: (AssetImage(
"images/profile_pic.png")), // picked file
fit: BoxFit.contain)),
),
),
SizedBox(height:MediaQuery.of(context).size.height * .016,),
Text(
AppSettings.userName,
style: fontTextStyle(20,Color(0XFF2A2A2A),FontWeight.w500),
),
Visibility(
visible:AppSettings.loginType.toString().toLowerCase()=='user',
child: Text(
AppSettings.email,
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
),),
Text(
AppSettings.phoneNumber,
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
),
],
),),
SizedBox(height:MediaQuery.of(context).size.height * .024,),
ListTile(
title: Row(
children: [
Image(
image: const AssetImage('images/logout_drawer.png'),
height: 25,
width: 25,
fit: BoxFit.fill),
SizedBox(width:MediaQuery.of(context).size.width * .04,),
Text('Logout', style: fontTextStyle(16,Color(0XFFE2483D),FontWeight.w400),),
],
),
onTap: () {
showLogoutAlertDialog(context);
},
),
],
),
),
)
),
body:
_screens[_currentIndex],
/*_body(),,*/
bottomNavigationBar: Padding(
padding:EdgeInsets.fromLTRB(0, 0, 0, 0) ,
child: BottomNavigationBar(
backgroundColor: Color(0XFFFFFFFF),
items: _bottomNavItems,
selectedItemColor: primaryColor, // Color of selected icon and text
unselectedItemColor: Color(0XFF939495), // Color of unselected icon and text
selectedLabelStyle: fontTextStyleHeight(10,primaryColor,FontWeight.w400,MediaQuery.of(context).size.height * .0032,),
unselectedLabelStyle: fontTextStyleHeight(10,Color(0XFF939495),FontWeight.w400,MediaQuery.of(context).size.height * .0032,),
currentIndex: _currentIndex,
onTap: _onItemTapped,
/*onTap: (index) {
switch (index) {
case 0:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Resources()),
);
break;
case 1:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => TankLevels()),
);
break;
case 3:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Consumption()),
);
break;
case 4:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SupplierManagementDashboard()),
);
break;
}
},*/
type: BottomNavigationBarType
.fixed, // Ensures all 6 items are visible
),
)
));
}
}
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"Hello! Welcome to ${AppSettings.buildingName}",
style: fontTextStyle(16,Color(0XFF2A2A2A),FontWeight.w600),
),
SizedBox(height:MediaQuery.of(context).size.height * .03,),
],
)
),
);
}
}
// Screens for each bottom navigation item