You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/views/pages/user/profile_page.dart

353 lines
19 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/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/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/user.dart';
import 'package:test_sa/models/user_rota_model.dart';
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
import 'package:test_sa/new_views/common_widgets/app_dashed_button.dart';
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
import 'package:test_sa/views/pages/user/update_user_contact_info_bottomsheet.dart';
import '../../../new_views/app_style/app_color.dart';
class ProfilePage extends StatefulWidget {
static const String id = "/user/profile";
const ProfilePage({Key? key}) : super(key: key);
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
late UserProvider _userProvider;
late SettingProvider _settingProvider;
late double _width;
late double _height;
User _user = User();
bool _firstTime = true;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
_userProvider = Provider.of<UserProvider>(context);
_settingProvider = Provider.of<SettingProvider>(context);
_width = MediaQuery.of(context).size.width;
_height = MediaQuery.of(context).size.height;
if (_firstTime) {
_user = User.fromJsonCons(_userProvider.user!.toJson());
_firstTime = false;
}
Color color = context.isDark ? AppColor.neutral10 : AppColor.neutral50;
return Scaffold(
key: _scaffoldKey,
appBar: DefaultAppBar(title: context.translation.myProfile),
body: Column(
children: [
ListView(
padding: const EdgeInsets.all(16),
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Consumer<UserProvider>(builder: (context, snapshot, _) {
return Stack(
alignment: Alignment.bottomRight,
children: [
CircleAvatar(
radius: 45,
backgroundColor: const Color(0xFFE4E5E6),
child: Padding(
padding: const EdgeInsets.all(1), // Border radius
child: ClipOval(
child: snapshot.profileImage != null
? Image.file(snapshot.profileImage!)
: (snapshot.user!.profilePhotoName?.isNotEmpty ?? false)
? Image.network(snapshot.user!.profilePhotoName!)
: const Icon(
Icons.person,
size: 50,
color: Colors.white,
),
),
),
),
// CircleAvatar(
// radius: 14,
// backgroundColor: AppColor.primary70,
// child: Padding(
// padding: const EdgeInsets.all(1), // Border radius
// child: snapshot.isLoading
// ? const SizedBox(height: 16, width: 16, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
// : const Icon(Icons.upload, size: 16, color: Colors.white),
// ),
// ).onPress(snapshot.isLoading
// ? null
// : () async {
// final pickedFile = await ImagePicker().pickImage(source: ImageSource.gallery, imageQuality: 70, maxWidth: 800, maxHeight: 800);
//
// if (pickedFile != null) {
// CroppedFile? croppedFile = await ImageCropper().cropImage(
// sourcePath: pickedFile.path,
// aspectRatio: CropAspectRatio(ratioX: 1, ratioY: 1),
// uiSettings: [
// AndroidUiSettings(
// toolbarTitle: 'ATOMS',
// toolbarColor: Colors.white,
// toolbarWidgetColor: color,
// initAspectRatio: CropAspectRatioPreset.square,
// lockAspectRatio: false,
// ),
// IOSUiSettings(title: 'ATOMS'),
// ],
// );
// if (croppedFile != null) {
// await snapshot.uploadProfileImage(_user.userID!, File(croppedFile.path));
// Provider.of<SettingProvider>(context, listen: false).setUser(_userProvider.user!);
// }
// }
// }),
],
);
}),
8.height,
(_user.username ?? "").heading3(context).custom(fontWeight: FontWeight.w600, color: context.isDark ? AppColor.neutral10 : AppColor.neutral50),
],
),
),
16.height,
Text(
'${context.translation.email}: ${_user.email ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
Text(
'${context.translation.phoneNumber}: ${_user.phoneNumber ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
Text(
'${context.translation.extensionNo}: ${_user.extensionNo ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
// if ((_user.phoneNumber ?? "").isNotEmpty) ...[
// const Divider().defaultStyle(context),
// 8.height,
// (_user.phoneNumber??"").heading5(context),
// 8.height,
// ],
// if ((_user.extensionNo ?? "").isNotEmpty) ...[
// const Divider().defaultStyle(context),
// 8.height,
// _user.extensionNo!.heading5(context),
// 8.height,
// ],
if ((_user.departmentName?.length ?? 0) > 0) const Divider().defaultStyle(context),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: _user.departmentName?.length ?? 0,
shrinkWrap: true,
padding: EdgeInsets.zero,
itemBuilder: (context, index) {
return (_user.departmentName![index] ?? "N/A").bodyText(context).paddingOnly(top: 4, bottom: 4);
},
),
if ((_user.clientName ?? "").isNotEmpty) ...[
const Divider().defaultStyle(context),
8.height,
_user.clientName!.heading5(context).custom(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50),
8.height,
],
Selector<UserProvider, bool>(
selector: (_, myModel) => myModel.isLoading, // Selects only the userName
builder: (_, isLoading, __) {
return AppDashedButton(
title: isLoading ? "Uploading..." : "Update Image",
height: 50,
width: MediaQuery.sizeOf(context).width / 2,
padding: EdgeInsets.all(4),
icon: isLoading
? const SizedBox(height: 16, width: 16, child: CircularProgressIndicator(color: AppColor.primary10, strokeWidth: 2))
: 'attachment_icon'.toSvgAsset(height: 24, width: 24),
buttonColor: AppColor.primary10,
onPressed: () async {
if (isLoading) return;
final pickedFile = await ImagePicker().pickImage(source: ImageSource.gallery, imageQuality: 70, maxWidth: 800, maxHeight: 800);
if (pickedFile != null) {
CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: pickedFile.path,
aspectRatio: CropAspectRatio(ratioX: 1, ratioY: 1),
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'ATOMS',
toolbarColor: Colors.white,
toolbarWidgetColor: color,
initAspectRatio: CropAspectRatioPreset.square,
lockAspectRatio: false,
),
IOSUiSettings(title: 'ATOMS'),
],
);
if (croppedFile != null) {
await context.userProvider.uploadProfileImage(_user.userID!, File(croppedFile.path));
Provider.of<SettingProvider>(context, listen: false).setUser(_userProvider.user!);
}
}
},
).center;
})
],
).toShadowContainer(context),
if (context.settingProvider.isUserFlowMedical)
FutureBuilder<UserRotaModel?>(
future: _userProvider.getUserRota(),
builder: (cxt, snapshot) {
bool isLoading = snapshot.connectionState == ConnectionState.waiting;
if ((!isLoading && (snapshot.hasError || !snapshot.hasData))) {
return const SizedBox();
}
return Container(
margin: const EdgeInsets.only(top: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Rota Details",
style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
),
8.height,
if (isLoading) ...[
Text(
'Shift Start Time Time',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
).toShimmer(context: context, isShow: isLoading),
4.height,
Text(
'Shift Actual Actual Start Time',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
).toShimmer(context: context, isShow: isLoading)
] else
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Text(
// 'Site: ${_user.clientName ?? "-"}',
// style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
// ),
Text(
'Shift Name: ${snapshot.data!.shiftName ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
Text(
'Break: ${snapshot.data!.breakTime ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
if (snapshot.data!.leaveTypeCode?.isNotEmpty ?? false)
SizedBox(
width: double.infinity,
child: Column(children: [
8.height,
Text(
snapshot.data!.leaveTypeCode ?? "",
style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120, fontWeight: FontWeight.w600),
),
Text(
snapshot.data!.leaveDescription ?? "",
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
]),
)
else ...[
Text(
'Shift Start Time: ${snapshot.data!.shiftName?.split('-').first.trim() ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
Text(
'Shift End Time: ${snapshot.data!.shiftName?.split('-').last.trim() ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
const Divider().defaultStyle(context),
Text(
'Swipe In: ${snapshot.data!.shTActualStartTime?.toTime ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
Text(
'Swipe Out: ${snapshot.data!.shTActualEndTime?.toTime ?? "-"}',
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
),
],
],
),
],
).toShadowContainer(context),
);
// if (!isDeviceSupported) {
// return Text("Your device did not support Fingerprint/Face ID.", style: AppTextStyles.tinyFont.copyWith(fontSize: 11, color: Colors.red));
// }
// return Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// "Fingerprint/Face ID".heading5(context),
// customSwitch(localAuth).onPress(() {
// checkForLocalAuth(localAuth);
// }),
// ],
// );
}),
],
).expanded,
FooterActionButton.footerContainer(
context: context,
child: AppFilledButton(
label: "Update Information",
buttonColor: context.isDark ? AppColor.primary10 : AppColor.neutral50,
onPressed: () {
context.showBottomSheet(
UpdateUserContactInfoBottomSheet(
_userProvider.user!.userID!,
uEmail: _user.email,
uPhoneNo: _user.phoneNumber,
uExtensionNo: _user.extensionNo,
onUpdate: (email, phoneNo, extensionNo) {
_userProvider.user!.email = email;
_userProvider.user!.phoneNumber = phoneNo;
_userProvider.user!.extensionNo = extensionNo;
_firstTime = true;
Provider.of<SettingProvider>(context, listen: false).setUser(_userProvider.user!);
},
),
title: "Update Information");
},
),
)
],
),
);
}
}