Skip to content
This repository was archived by the owner on Jan 5, 2021. It is now read-only.

Commit 7b491e6

Browse files
committed
Remove one per day request in download from settings page
1 parent 0fdec6e commit 7b491e6

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

lib/pages/download_ussd_page.dart

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,44 @@ class _DownloadUssdPageState extends State<DownloadUssdPage> {
3131
try {
3232
var prefs = await SharedPreferences.getInstance();
3333
var lastHash = prefs.getString('hash');
34-
var lastDay = prefs.getInt('day');
3534
var actualDay = DateTime.now().day;
36-
if (lastDay == null || lastDay != actualDay) {
37-
var resp = await get(
38-
'https://todo-devs.github.io/todo-json/hash.json',
39-
headers: {
40-
'Accept-Encoding': 'gzip, deflate, br',
41-
},
42-
);
43-
if (resp.statusCode == 200) {
44-
var json = jsonDecode(utf8.decode(resp.bodyBytes));
45-
var actualHash = json['hash'];
46-
if (actualHash != lastHash) {
47-
var resp = await get(
48-
'https://todo-devs.github.io/todo-json/config.json',
49-
headers: {
50-
'Accept-Encoding': 'gzip, deflate, br',
51-
},
35+
var resp = await get(
36+
'https://todo-devs.github.io/todo-json/hash.json',
37+
headers: {
38+
'Accept-Encoding': 'gzip, deflate, br',
39+
},
40+
);
41+
if (resp.statusCode == 200) {
42+
var json = jsonDecode(utf8.decode(resp.bodyBytes));
43+
var actualHash = json['hash'];
44+
if (actualHash != lastHash) {
45+
var resp = await get(
46+
'https://todo-devs.github.io/todo-json/config.json',
47+
headers: {
48+
'Accept-Encoding': 'gzip, deflate, br',
49+
},
50+
);
51+
if (resp.statusCode == 200) {
52+
var body = utf8.decode(resp.bodyBytes);
53+
var parsedJson = jsonDecode(body);
54+
UssdRoot.fromJson(parsedJson);
55+
prefs.setString('hash', actualHash);
56+
prefs.setString('config', body);
57+
} else {
58+
throw Exception(
59+
'Request failed: ${resp.request.url}\n'
60+
'StatusCode: ${resp.statusCode}\n'
61+
'Body: ${resp.body}',
5262
);
53-
if (resp.statusCode == 200) {
54-
var body = utf8.decode(resp.bodyBytes);
55-
var parsedJson = jsonDecode(body);
56-
UssdRoot.fromJson(parsedJson);
57-
prefs.setString('hash', actualHash);
58-
prefs.setString('config', body);
59-
} else {
60-
throw Exception(
61-
'Request failed: ${resp.request.url}\n'
62-
'StatusCode: ${resp.statusCode}\n'
63-
'Body: ${resp.body}',
64-
);
65-
}
6663
}
67-
prefs.setInt('day', actualDay);
68-
} else {
69-
throw Exception(
70-
'Request failed: ${resp.request.url}\n'
71-
'StatusCode: ${resp.statusCode}\n'
72-
'Body: ${resp.body}',
73-
);
7464
}
65+
prefs.setInt('day', actualDay);
66+
} else {
67+
throw Exception(
68+
'Request failed: ${resp.request.url}\n'
69+
'StatusCode: ${resp.statusCode}\n'
70+
'Body: ${resp.body}',
71+
);
7572
}
7673
Navigator.pushReplacement(
7774
context,

0 commit comments

Comments
 (0)