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,16 +41,13 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
// onChange: (newProPic) {}, // onChange: (newProPic) {},
// ), // ),
//print(widget.propicFile); //print(widget.propicFile);
ImageProvider logoFrame =
MzanziInnovationHub.of(context)!.theme.logoFrame();
if (widget.propicFile != null) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pushNamed( Navigator.of(context).pushNamed(
'/mzansi-profile', '/mzansi-profile',
arguments: AppProfileUpdateArguments( arguments:
widget.signedInUser, widget.propicFile), AppProfileUpdateArguments(widget.signedInUser, widget.propicFile),
); );
}, },
child: MihCircleAvatar( child: MihCircleAvatar(
@@ -61,6 +58,8 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
onChange: (_) {}, onChange: (_) {},
userSelectedfile: null, userSelectedfile: null,
frameColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), frameColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
backgroundColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
), ),
// MIHProfilePicture( // MIHProfilePicture(
// profilePictureFile: widget.propicFile, // profilePictureFile: widget.propicFile,
@@ -92,12 +91,6 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
// ], // ],
// ), // ),
); );
} else {
return 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),