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,
frameColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
backgroundColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(),
onChange: (selectedImage) {
setState(() {
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 PlatformFile? userSelectedfile;
final Color frameColor;
final Color? backgroundColor;
const MihCircleAvatar({
super.key,
required this.imageFile,
@@ -21,6 +22,7 @@ class MihCircleAvatar extends StatefulWidget {
required this.fileNameController,
required this.userSelectedfile,
required this.frameColor,
required this.backgroundColor,
required this.onChange,
});
@@ -31,11 +33,29 @@ class MihCircleAvatar extends StatefulWidget {
class _MihCircleAvatarState extends State<MihCircleAvatar> {
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
void initState() {
super.initState();
print("Avatar started");
setState(() {
imagePreview = widget.imageFile;
imagePreview = getAvatar();
});
}
@@ -51,7 +71,7 @@ class _MihCircleAvatarState extends State<MihCircleAvatar> {
children: [
CircleAvatar(
radius: widget.width / 2.2,
backgroundColor: widget.frameColor,
backgroundColor: widget.backgroundColor,
backgroundImage: imagePreview,
),
FittedBox(

View File

@@ -41,63 +41,56 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
// onChange: (newProPic) {},
// ),
//print(widget.propicFile);
ImageProvider logoFrame =
MzanziInnovationHub.of(context)!.theme.logoFrame();
if (widget.propicFile != null) {
return GestureDetector(
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(
'/mzansi-profile',
arguments: AppProfileUpdateArguments(
widget.signedInUser, 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(
return GestureDetector(
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(
'/mzansi-profile',
arguments:
AppProfileUpdateArguments(widget.signedInUser, widget.propicFile),
);
},
child: MihCircleAvatar(
imageFile: widget.propicFile,
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

View File

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

View File

@@ -35,17 +35,6 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
ImageProvider<Object>? propicFile;
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) {
if (signedInUser.fname == "") {
return true;
@@ -249,7 +238,9 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
business: snapshot.data!.business,
patient: snapshot.data!.patient,
notifications: snapshot.data!.notifi,
propicFile: isPictureAvailable(snapshot.data!.profilePicUrl),
propicFile: snapshot.data!.profilePicUrl != ""
? NetworkImage(snapshot.data!.profilePicUrl)
: null,
isUserNew: isUserNew(snapshot.requireData.signedInUser),
isBusinessUser: isBusinessUser(snapshot.requireData.signedInUser),
isBusinessUserNew: isBusinessUserNew(snapshot.data!.businessUser),