circle avatar to handle null

This commit is contained in:
2025-04-25 14:19:20 +02:00
parent 97ce2672a2
commit 62b092baf8
7 changed files with 78 additions and 70 deletions

View File

@@ -125,6 +125,8 @@ class _PackageToolOneState extends State<PackageToolOne> {
userSelectedfile: file, userSelectedfile: file,
frameColor: frameColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(), MzanziInnovationHub.of(context)!.theme.secondaryColor(),
backgroundColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(),
onChange: (selectedImage) { onChange: (selectedImage) {
setState(() { setState(() {
file = selectedImage; file = selectedImage;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@@ -13,6 +13,7 @@ class MihCircleAvatar extends StatefulWidget {
final onChange; final onChange;
final PlatformFile? userSelectedfile; final PlatformFile? userSelectedfile;
final Color frameColor; final Color frameColor;
final Color? backgroundColor;
const MihCircleAvatar({ const MihCircleAvatar({
super.key, super.key,
required this.imageFile, required this.imageFile,
@@ -21,6 +22,7 @@ class MihCircleAvatar extends StatefulWidget {
required this.fileNameController, required this.fileNameController,
required this.userSelectedfile, required this.userSelectedfile,
required this.frameColor, required this.frameColor,
required this.backgroundColor,
required this.onChange, required this.onChange,
}); });
@@ -31,11 +33,29 @@ class MihCircleAvatar extends StatefulWidget {
class _MihCircleAvatarState extends State<MihCircleAvatar> { class _MihCircleAvatarState extends State<MihCircleAvatar> {
late ImageProvider<Object>? imagePreview; late ImageProvider<Object>? imagePreview;
ImageProvider<Object>? getAvatar() {
Color dark = const Color(0XFF3A4454);
if (widget.imageFile == null) {
if (widget.backgroundColor == dark) {
print("here in light icon");
return const AssetImage(
'lib/mih_components/mih_package_components/assets/images/i-dont-know-light.png');
} else {
print("here in dark icon");
return const AssetImage(
'lib/mih_components/mih_package_components/assets/images/i-dont-know-dark.png');
}
} else {
return widget.imageFile;
}
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
print("Avatar started");
setState(() { setState(() {
imagePreview = widget.imageFile; imagePreview = getAvatar();
}); });
} }
@@ -51,7 +71,7 @@ class _MihCircleAvatarState extends State<MihCircleAvatar> {
children: [ children: [
CircleAvatar( CircleAvatar(
radius: widget.width / 2.2, radius: widget.width / 2.2,
backgroundColor: widget.frameColor, backgroundColor: widget.backgroundColor,
backgroundImage: imagePreview, backgroundImage: imagePreview,
), ),
FittedBox( FittedBox(

View File

@@ -41,63 +41,56 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
// onChange: (newProPic) {}, // onChange: (newProPic) {},
// ), // ),
//print(widget.propicFile); //print(widget.propicFile);
ImageProvider logoFrame = return GestureDetector(
MzanziInnovationHub.of(context)!.theme.logoFrame(); onTap: () {
if (widget.propicFile != null) { Navigator.of(context).pop();
return GestureDetector( Navigator.of(context).pushNamed(
onTap: () { '/mzansi-profile',
Navigator.of(context).pop(); arguments:
Navigator.of(context).pushNamed( AppProfileUpdateArguments(widget.signedInUser, widget.propicFile),
'/mzansi-profile', );
arguments: AppProfileUpdateArguments( },
widget.signedInUser, widget.propicFile), child: MihCircleAvatar(
); imageFile: widget.propicFile,
},
child: MihCircleAvatar(
imageFile: widget.propicFile,
width: 60,
editable: false,
fileNameController: proPicController,
onChange: (_) {},
userSelectedfile: null,
frameColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
),
// MIHProfilePicture(
// profilePictureFile: widget.propicFile,
// proPicController: proPicController,
// proPic: null,
// width: 60,
// radius: 27,
// drawerMode: true,
// editable: false,
// frameColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
// onChange: (newProPic) {},
// ),
// Stack(
// alignment: Alignment.center,
// fit: StackFit.loose,
// children: [
// CircleAvatar(
// backgroundColor:
// MzanziInnovationHub.of(context)!.theme.primaryColor(),
// backgroundImage: widget.propicFile,
// //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'),
// radius: 27,
// ),
// SizedBox(
// width: 60,
// child: Image(image: logoFrame),
// )
// ],
// ),
);
} else {
return SizedBox(
width: 60, width: 60,
child: Image(image: logoFrame), editable: false,
); fileNameController: proPicController,
} onChange: (_) {},
userSelectedfile: null,
frameColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
backgroundColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
),
// MIHProfilePicture(
// profilePictureFile: widget.propicFile,
// proPicController: proPicController,
// proPic: null,
// width: 60,
// radius: 27,
// drawerMode: true,
// editable: false,
// frameColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
// onChange: (newProPic) {},
// ),
// Stack(
// alignment: Alignment.center,
// fit: StackFit.loose,
// children: [
// CircleAvatar(
// backgroundColor:
// MzanziInnovationHub.of(context)!.theme.primaryColor(),
// backgroundImage: widget.propicFile,
// //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'),
// radius: 27,
// ),
// SizedBox(
// width: 60,
// child: Image(image: logoFrame),
// )
// ],
// ),
);
} }
@override @override

View File

@@ -109,6 +109,8 @@ class _MihHomeState extends State<MihHome> {
userSelectedfile: null, userSelectedfile: null,
// frameColor: frameColor, // frameColor: frameColor,
frameColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), frameColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
backgroundColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(),
onChange: (_) {}, onChange: (_) {},
), ),
// MIHProfilePicture( // MIHProfilePicture(

View File

@@ -35,17 +35,6 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
ImageProvider<Object>? propicFile; ImageProvider<Object>? propicFile;
int _selcetedIndex = 0; int _selcetedIndex = 0;
ImageProvider<Object>? isPictureAvailable(String url) {
if (url == "") {
return const AssetImage(
'lib/mih_components/mih_package_components/assets/images/i-dont-know-2.png');
} else if (url != "") {
return NetworkImage(url);
} else {
return null;
}
}
bool isUserNew(AppUser signedInUser) { bool isUserNew(AppUser signedInUser) {
if (signedInUser.fname == "") { if (signedInUser.fname == "") {
return true; return true;
@@ -249,7 +238,9 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
business: snapshot.data!.business, business: snapshot.data!.business,
patient: snapshot.data!.patient, patient: snapshot.data!.patient,
notifications: snapshot.data!.notifi, notifications: snapshot.data!.notifi,
propicFile: isPictureAvailable(snapshot.data!.profilePicUrl), propicFile: snapshot.data!.profilePicUrl != ""
? NetworkImage(snapshot.data!.profilePicUrl)
: null,
isUserNew: isUserNew(snapshot.requireData.signedInUser), isUserNew: isUserNew(snapshot.requireData.signedInUser),
isBusinessUser: isBusinessUser(snapshot.requireData.signedInUser), isBusinessUser: isBusinessUser(snapshot.requireData.signedInUser),
isBusinessUserNew: isBusinessUserNew(snapshot.data!.businessUser), isBusinessUserNew: isBusinessUserNew(snapshot.data!.businessUser),