fix home screen data syncing and caching and add manual sync data button

This commit is contained in:
yaso 2026-06-25 11:58:10 +02:00
parent f19a316be8
commit d42337fc6c
3 changed files with 72 additions and 13 deletions

View file

@ -171,9 +171,7 @@ class MihGoRouter {
path: MihGoRouterPaths.mihHome,
builder: (BuildContext context, GoRouterState state) {
KenLogger.success("MihGoRouter: mihHome");
return MihHome(
key: UniqueKey(),
);
return MihHome();
},
routes: [
// ========================== About MIH ==================================

View file

@ -42,9 +42,11 @@ class _MihHomeState extends State<MihHome> {
context.read<MzansiProfileProvider>();
mzansiProfileProvider.loadCachedProfileState();
if (mzansiProfileProvider.user == null) {
await mzansiProfileProvider.syncWithCloudPipeline();
await mzansiProfileProvider.syncWithMihServerData();
} else {
mzansiProfileProvider.syncWithMihServerData();
}
}
}
@override
void dispose() {
@ -74,18 +76,26 @@ class _MihHomeState extends State<MihHome> {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
if (mzansiProfileProvider.user == null) {
return Scaffold(
body: Center(
child: Mihloadingcircle(),
),
);
}
if (mzansiProfileProvider.user == null) {
return Scaffold(
body: Center(
child: Mihloadingcircle(),
),
);
}
return Stack(
children: [
RefreshIndicator(
key: mzansiProfileProvider.refreshIndicatorKey,
onRefresh: () async {
await mzansiProfileProvider.syncWithCloudPipeline();
await mzansiProfileProvider.syncWithMihServerData();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
MihSnackBar(
child: Text("Data Synced with MIH Server."),
),
);
}
},
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),

View file

@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
import 'package:provider/provider.dart';
class MihHomeRefreshTile extends StatefulWidget {
final double packageSize;
const MihHomeRefreshTile({
super.key,
required this.packageSize,
});
@override
State<MihHomeRefreshTile> createState() => _MihHomeRefreshTileState();
}
class _MihHomeRefreshTileState extends State<MihHomeRefreshTile> {
@override
Widget build(BuildContext context) {
return Consumer<MzansiProfileProvider>(
builder: (BuildContext context, MzansiProfileProvider profileProvider,
Widget? child) {
return MihPackageTile(
onTap: profileProvider.triggerRefresh,
packageName: "Sync Data",
packageIcon: Stack(
alignment: Alignment.center,
children: [
Icon(
MihIcons.mihRing,
color: MihColors.secondary(),
),
Center(
child: Transform.scale(
scale: 0.75,
origin: Offset(-4, 0),
child: Icon(
Icons.cloud_sync_rounded,
color: MihColors.secondary(),
),
),
),
],
),
iconSize: widget.packageSize,
textColor: MihColors.secondary(),
);
},
);
}
}