fix home screen data syncing and caching and add manual sync data button
This commit is contained in:
parent
f19a316be8
commit
d42337fc6c
3 changed files with 72 additions and 13 deletions
|
|
@ -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 ==================================
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,11 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
|
@ -74,18 +76,26 @@ class _MihHomeState extends State<MihHome> {
|
||||||
return Consumer<MzansiProfileProvider>(
|
return Consumer<MzansiProfileProvider>(
|
||||||
builder: (BuildContext context,
|
builder: (BuildContext context,
|
||||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||||
if (mzansiProfileProvider.user == null) {
|
if (mzansiProfileProvider.user == null) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Mihloadingcircle(),
|
child: Mihloadingcircle(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
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(),
|
||||||
|
|
|
||||||
|
|
@ -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(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue