flutter linting

This commit is contained in:
unknown
2022-01-05 13:02:22 +01:00
parent 79f6ef4c50
commit 339dbea1ef
26 changed files with 226 additions and 143 deletions

View File

@@ -1,3 +1,5 @@
// ignore_for_file: avoid_print
import 'dart:convert';
import 'package:filcnaplo/models/config.dart';
@@ -11,23 +13,23 @@ import 'package:connectivity_plus/connectivity_plus.dart';
class FilcAPI {
// Public API
static const SCHOOL_LIST = "https://filcnaplo.hu/v2/school_list.json";
static const NEWS = "https://filcnaplo.hu/v2/news.json";
static const SUPPORTERS = "https://filcnaplo.hu/v2/supporters.json";
static const schoolList = "https://filcnaplo.hu/v2/school_list.json";
static const news = "https://filcnaplo.hu/v2/news.json";
static const supporters = "https://filcnaplo.hu/v2/supporters.json";
// Private API
static const CONFIG = "https://api.filcnaplo.hu/config";
static const REPORT = "https://api.filcnaplo.hu/report";
static const config = "https://api.filcnaplo.hu/config";
static const reportApi = "https://api.filcnaplo.hu/report";
// Updates
static const REPO = "filc/naplo";
static const RELEASES = "https://api.github.com/repos/$REPO/releases";
static const repo = "filc/naplo";
static const releases = "https://api.github.com/repos/$repo/releases";
static Future<bool> checkConnectivity() async => (await Connectivity().checkConnectivity()) != ConnectivityResult.none;
static Future<bool> checkConnectivity() async => (await Connectivity().checkConnectivity()) != ConnectivityResult.none;
static Future<List<School>?> getSchools() async {
try {
http.Response res = await http.get(Uri.parse(SCHOOL_LIST));
http.Response res = await http.get(Uri.parse(schoolList));
if (res.statusCode == 200) {
List<School> schools = (jsonDecode(res.body) as List).cast<Map>().map((json) => School.fromJson(json)).toList();
@@ -52,12 +54,12 @@ class FilcAPI {
};
try {
http.Response res = await http.get(Uri.parse(CONFIG), headers: headers);
http.Response res = await http.get(Uri.parse(config), headers: headers);
if (res.statusCode == 200) {
return Config.fromJson(jsonDecode(res.body));
} else if (res.statusCode == 429) {
res = await http.get(Uri.parse(CONFIG));
res = await http.get(Uri.parse(config));
if (res.statusCode == 200) return Config.fromJson(jsonDecode(res.body));
}
throw "HTTP ${res.statusCode}: ${res.body}";
@@ -68,7 +70,7 @@ class FilcAPI {
static Future<List<News>?> getNews() async {
try {
http.Response res = await http.get(Uri.parse(NEWS));
http.Response res = await http.get(Uri.parse(news));
if (res.statusCode == 200) {
return (jsonDecode(res.body) as List).cast<Map>().map((e) => News.fromJson(e)).toList();
@@ -82,7 +84,7 @@ class FilcAPI {
static Future<Supporters?> getSupporters() async {
try {
http.Response res = await http.get(Uri.parse(SUPPORTERS));
http.Response res = await http.get(Uri.parse(supporters));
if (res.statusCode == 200) {
return Supporters.fromJson(jsonDecode(res.body));
@@ -96,7 +98,7 @@ class FilcAPI {
static Future<List<Release>?> getReleases() async {
try {
http.Response res = await http.get(Uri.parse(RELEASES));
http.Response res = await http.get(Uri.parse(releases));
if (res.statusCode == 200) {
return (jsonDecode(res.body) as List).cast<Map>().map((e) => Release.fromJson(e)).toList();
@@ -109,7 +111,7 @@ class FilcAPI {
}
static Future<http.StreamedResponse?> downloadRelease(Release release) {
if (release.downloads.length > 0) {
if (release.downloads.isNotEmpty) {
try {
var client = http.Client();
var request = http.Request('GET', Uri.parse(release.downloads.first));
@@ -124,7 +126,7 @@ class FilcAPI {
static Future<void> sendReport(ErrorReport report) async {
try {
http.Response res = await http.post(Uri.parse(REPORT), body: {
http.Response res = await http.post(Uri.parse(reportApi), body: {
"os": report.os,
"version": report.version,
"error": report.error,