Skip to content

Commit

Permalink
fix cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocarlini committed Feb 6, 2024
1 parent 0442a03 commit 881bd12
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
26 changes: 19 additions & 7 deletions lib/components/info_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class InfoCell extends StatelessWidget {
if (snapshot.hasData) {
if (snapshot.data.contains('.')) {
children = buildOk(snapshot.data);
saveInState(context, snapshot);
saveInState(context, snapshot.data);
} else if (snapshot.data.contains('Empty Body')) {
children = buildWarning(snapshot.data);
saveInState(context, snapshot);
saveInState(context, snapshot.data);
} else {
children = buildError(snapshot.data);
}
Expand All @@ -55,16 +55,16 @@ class InfoCell extends StatelessWidget {
});
}

void saveInState(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
void saveInState(BuildContext context, String value) {
if (context.mounted) {
if (env == "DEV") {
context.read<AppCubit>().addDev(project['product'], snapshot.data);
context.read<AppCubit>().addDev(project['product'], value);
}
if (env == "UAT") {
context.read<AppCubit>().addUat(project['product'], snapshot.data);
context.read<AppCubit>().addUat(project['product'], value);
}
if (env == "PROD") {
context.read<AppCubit>().addProd(project['product'], snapshot.data);
context.read<AppCubit>().addProd(project['product'], value);
}
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ class InfoCell extends StatelessWidget {
];
}

List<Widget> buildOk(version) {
List<Widget> buildOk(String version) {
return <Widget>[
const Icon(
Icons.check_circle_outline,
Expand Down Expand Up @@ -205,6 +205,18 @@ class InfoCell extends StatelessWidget {
}

var key = "${project['product']}-info-$env";

// var response = await http.get(Uri.parse(url));
//
// if (response.statusCode == 200 && response.bodyBytes.isNotEmpty) {
// return jsonDecode(response.body)['version'] ?? 'No Info Version';
// } else {
// if (response.bodyBytes.isEmpty) {
// return 'Empty Body';
// } else {
// return response.statusCode.toString();
// }
// }
return remember(key, () async {
var response = await http.get(Uri.parse(url));

Expand Down
30 changes: 28 additions & 2 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ class HomePageState extends State<HomePage> {
return Stream.periodic(period, f).asyncMap((event) async => await event);
}

void updateData() {
emptyCache();
void updateData() async {
await emptyCache();

if (context.mounted) {
context.read<AppCubit>().empty();
Navigator.popAndPushNamed(context, '/');
}
}

Expand All @@ -161,6 +163,30 @@ class HomePageState extends State<HomePage> {
prefs.remove(key4);
}
});
projectsTouchPoint.forEach((namespace, value) {
for (var repo in value) {
var key1 = "${repo['product']}-info-DEV";
var key2 = "${repo['product']}-info-UAT";
var key3 = "${repo['product']}-info-PROD";
var key4 = "${repo['product']}-release";
prefs.remove(key1);
prefs.remove(key2);
prefs.remove(key3);
prefs.remove(key4);
}
});
projectsVAS.forEach((namespace, value) {
for (var repo in value) {
var key1 = "${repo['product']}-info-DEV";
var key2 = "${repo['product']}-info-UAT";
var key3 = "${repo['product']}-info-PROD";
var key4 = "${repo['product']}-release";
prefs.remove(key1);
prefs.remove(key2);
prefs.remove(key3);
prefs.remove(key4);
}
});
prefs.remove(lastUpdatedKey);
}
}

0 comments on commit 881bd12

Please sign in to comment.