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.
mohemm-flutter-app/lib/ui/screens/profile/profile_screen.dart

152 lines
5.5 KiB
Dart

import 'dart:ui';
import 'dart:convert';
import 'dart:ui';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:mohem_flutter_app/api/profile_api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/get_employee_basic_details.model.dart';
import 'package:mohem_flutter_app/models/member_information_list_model.dart';
import 'package:mohem_flutter_app/ui/screens/profile/widgets/header.dart';
import 'package:mohem_flutter_app/ui/screens/profile/widgets/profile_panel.dart';
import 'package:mohem_flutter_app/widgets/bottom_sheet.dart';
// todo '@sultan' kindly follow structure of code written. use extension methods for widgets and dont hard code strings, use localizations
class ProfileScreen extends StatefulWidget {
const ProfileScreen({Key? key}) : super(key: key);
@override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
late MemberInformationListModel memberInformationList;
final ImagePicker _picker = ImagePicker();
List<GetEmployeeBasicDetailsList> getEmployeeBasicDetailsList = [];
@override
void initState() {
super.initState();
memberInformationList = AppState().memberInformationList!;
setState(() {});
//getEmployeeBasicDetails();
}
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
backgroundColor: const Color(0xffefefef),
body: Stack(children: [
Container(
height: 300,
margin: EdgeInsets.only(top: 50),
decoration: BoxDecoration(image: DecorationImage(image: MemoryImage(Utils.getPostBytes(memberInformationList.eMPLOYEEIMAGE)), fit: BoxFit.cover)),
child: new BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: new Container(
decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),
),
),
),
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 80,
),
Container(
padding: EdgeInsets.only(left: 15, right: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
),
InkWell(
onTap: () {
startImageSheet();
},
child: Container(
padding: EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 5),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(15), color: Colors.black.withOpacity(.3)),
child: Row(
children: [
Icon(Icons.photo, color: Colors.white),
Text(
'Edit',
style: TextStyle(color: Colors.white, fontSize: 12),
)
],
),
),
),
],
),
),
HeaderPanel(memberInformationList),
ProfilePanle(memberInformationList)
],
),
)
]));
}
void startImageSheet() {
showMyBottomSheet(context,
child: Column(
children: [
Container(
padding: EdgeInsets.only(left: 20, right: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text(LocaleKeys.ok.tr()), Text(LocaleKeys.cancel.tr())],
)),
BottomSheetItem(
onTap: () {
openGallery(false);
},
title: 'Open Gallery',
icon: Icons.browse_gallery_outlined,
),
BottomSheetItem(
onTap: () {
openGallery(true);
},
title: 'Open Camera',
icon: Icons.camera,
)
],
));
}
void openGallery(bool isCamera) async {
final XFile? image = await _picker.pickImage(source: isCamera ? ImageSource.camera : ImageSource.gallery);
if (image != null) {
String img = base64.encode(await image!.readAsBytes());
Utils.showLoading(context);
dynamic empImageUpdteResp = await ProfileApiClient().updateEmpImage(img);
Utils.hideLoading(context);
if (empImageUpdteResp['P_RETURN_STATUS'] == 'S') {
setState(() {
memberInformationList.eMPLOYEEIMAGE = img;
});
}
}
}
}