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, path: MihGoRouterPaths.mihHome,
builder: (BuildContext context, GoRouterState state) { builder: (BuildContext context, GoRouterState state) {
KenLogger.success("MihGoRouter: mihHome"); KenLogger.success("MihGoRouter: mihHome");
return MihHome( return MihHome();
key: UniqueKey(),
);
}, },
routes: [ routes: [
// ========================== About MIH ================================== // ========================== About MIH ==================================

View file

@ -42,7 +42,9 @@ class _MihHomeState extends State<MihHome> {
context.read<MzansiProfileProvider>(); context.read<MzansiProfileProvider>();
mzansiProfileProvider.loadCachedProfileState(); mzansiProfileProvider.loadCachedProfileState();
if (mzansiProfileProvider.user == null) { if (mzansiProfileProvider.user == null) {
await mzansiProfileProvider.syncWithCloudPipeline(); await mzansiProfileProvider.syncWithMihServerData();
} else {
mzansiProfileProvider.syncWithMihServerData();
} }
} }
@ -84,8 +86,16 @@ class _MihHomeState extends State<MihHome> {
return Stack( return Stack(
children: [ children: [
RefreshIndicator( RefreshIndicator(
key: mzansiProfileProvider.refreshIndicatorKey,
onRefresh: () async { 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( child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(), 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(),
);
},
);
}
}