profile Picture fix

This commit is contained in:
2024-08-28 20:41:31 +02:00
parent 5d67e2549f
commit 4fc7f31943
3 changed files with 42 additions and 59 deletions

View File

@@ -55,7 +55,9 @@ class _MIHAppDrawerState extends State<MIHAppDrawer>
} }
Future<String> getFileUrlApiCall(String filePath) async { Future<String> getFileUrlApiCall(String filePath) async {
if (AppEnviroment.getEnv() == "Dev") { if (widget.signedInUser.pro_pic_path == "") {
return "";
} else if (AppEnviroment.getEnv() == "Dev") {
return "${AppEnviroment.baseFileUrl}/mih/$filePath"; return "${AppEnviroment.baseFileUrl}/mih/$filePath";
} else { } else {
var url = "${AppEnviroment.baseApiUrl}/minio/pull/file/$filePath/prod"; var url = "${AppEnviroment.baseApiUrl}/minio/pull/file/$filePath/prod";
@@ -81,11 +83,9 @@ class _MIHAppDrawerState extends State<MIHAppDrawer>
@override @override
void initState() { void initState() {
if (widget.signedInUser.pro_pic_path.isNotEmpty) { setState(() {
setState(() { proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path);
proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path); });
});
}
_controller = GifController(vsync: this); _controller = GifController(vsync: this);
super.initState(); super.initState();
} }
@@ -118,7 +118,7 @@ class _MIHAppDrawerState extends State<MIHAppDrawer>
future: proPicUrl, future: proPicUrl,
builder: (BuildContext context, snapshot) { builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) { if (snapshot.hasData && snapshot.data != "") {
return Stack( return Stack(
alignment: Alignment.center, alignment: Alignment.center,
fit: StackFit.loose, fit: StackFit.loose,
@@ -137,32 +137,16 @@ class _MIHAppDrawerState extends State<MIHAppDrawer>
], ],
); );
} else { } else {
return Center( return SizedBox(
child: Text( width: 60,
'${snapshot.error} occurred', child: Image(image: logoThemeSwitch),
style: const TextStyle(fontSize: 18),
),
); );
} }
} else { } else {
return SizedBox( return Center(
width: 60, child: Text(
child: Gif( '${snapshot.error} occurred',
image: MzanziInnovationHub.of(context)! style: const TextStyle(fontSize: 18),
.theme
.loadingImage(),
controller:
_controller, // if duration and fps is null, original gif fps will be used.
fps: 15,
//duration: const Duration(seconds: 3),
autostart: Autostart.loop,
placeholder: (context) => const Center(
child: CircularProgressIndicator(),
),
onFetchCompleted: () {
_controller.reset();
_controller.forward();
},
), ),
); );
} }

View File

@@ -45,7 +45,9 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate>
late final GifController _controller; late final GifController _controller;
Future<String> getFileUrlApiCall(String filePath) async { Future<String> getFileUrlApiCall(String filePath) async {
if (AppEnviroment.getEnv() == "Dev") { if (widget.signedInUser.pro_pic_path == "") {
return "";
} else if (AppEnviroment.getEnv() == "Dev") {
return "${AppEnviroment.baseFileUrl}/mih/$filePath"; return "${AppEnviroment.baseFileUrl}/mih/$filePath";
} else { } else {
var url = "${AppEnviroment.baseApiUrl}/minio/pull/file/$filePath/prod"; var url = "${AppEnviroment.baseApiUrl}/minio/pull/file/$filePath/prod";
@@ -222,12 +224,10 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate>
var proPicName = ""; var proPicName = "";
if (widget.signedInUser.pro_pic_path.isNotEmpty) { if (widget.signedInUser.pro_pic_path.isNotEmpty) {
proPicName = widget.signedInUser.pro_pic_path.split("/").last; proPicName = widget.signedInUser.pro_pic_path.split("/").last;
setState(() {
proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path);
});
} }
_controller = GifController(vsync: this); _controller = GifController(vsync: this);
setState(() { setState(() {
proPicUrl = getFileUrlApiCall(widget.signedInUser.pro_pic_path);
proPicController.text = proPicName; proPicController.text = proPicName;
fnameController.text = widget.signedInUser.fname; fnameController.text = widget.signedInUser.fname;
lnameController.text = widget.signedInUser.lname; lnameController.text = widget.signedInUser.lname;
@@ -270,7 +270,7 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate>
future: proPicUrl, future: proPicUrl,
builder: (BuildContext context, snapshot) { builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) { if (snapshot.hasData && snapshot.data != "") {
return Stack( return Stack(
alignment: Alignment.center, alignment: Alignment.center,
fit: StackFit.loose, fit: StackFit.loose,
@@ -292,32 +292,18 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate>
], ],
); );
} else { } else {
return Center( return SizedBox(
child: Text( width: 110,
'${snapshot.error} occurred', child: Image(
style: const TextStyle(fontSize: 18), image: MzanziInnovationHub.of(context)!
), .theme
); .altLogoImage()));
} }
} else { } else {
return SizedBox( return Center(
width: 110, child: Text(
child: Gif( '${snapshot.error} occurred',
image: MzanziInnovationHub.of(context)! style: const TextStyle(fontSize: 18),
.theme
.loadingImage(),
controller:
_controller, // if duration and fps is null, original gif fps will be used.
fps: 15,
//duration: const Duration(seconds: 3),
autostart: Autostart.loop,
placeholder: (context) => const Center(
child: CircularProgressIndicator(),
),
onFetchCompleted: () {
_controller.reset();
_controller.forward();
},
), ),
); );
} }

View File

@@ -164,6 +164,19 @@ class MyTheme {
return loading; return loading;
} }
AssetImage altLoadingImage() {
if (mode == "Dark") {
loading = const AssetImage(
'images/loading_dark.gif',
);
} else {
loading = const AssetImage(
'images/loading_light.gif',
);
}
return loading;
}
Color primaryColor() { Color primaryColor() {
if (mode == "Dark") { if (mode == "Dark") {
_mainColor = 0XFF3A4454; _mainColor = 0XFF3A4454;