Skip to content

Commit

Permalink
chore: format code with dart format (#71)
Browse files Browse the repository at this point in the history
This PR formats all code with dart format and adds a step to the CI so that it will be checked on every push and PR.
  • Loading branch information
denysvitali authored Apr 5, 2024
1 parent 43b9fe6 commit 056b2d7
Show file tree
Hide file tree
Showing 66 changed files with 1,563 additions and 1,349 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/flutter-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Flutter Check Format

on:
pull_request: {}
push: {}

jobs:
release:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup Flutter
uses: subosito/flutter-action@v1
with:
channel: stable
- name: Check Dart Format
run: dart format --set-exit-if-changed .
34 changes: 17 additions & 17 deletions lib/api/bucket_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ class BucketAPIService extends APIService implements BucketService {
return client
.put('/projects/$projectId/buckets', body: bucket.toJSON())
.then((response) {
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
}

@override
Future delete(int projectId, int bucketId) {
return client
.delete('/projects/$projectId/buckets/$bucketId');
return client.delete('/projects/$projectId/buckets/$bucketId');
}

/* Not implemented in the Vikunja API
Expand All @@ -35,13 +34,13 @@ class BucketAPIService extends APIService implements BucketService {
@override
Future<Response?> getAllByList(int projectId,
[Map<String, List<String>>? queryParameters]) {
return client
.get('/projects/$projectId/buckets', queryParameters)
.then((response) => response != null ? new Response(
convertList(response.body, (result) => Bucket.fromJSON(result)),
response.statusCode,
response.headers
) : null);
return client.get('/projects/$projectId/buckets', queryParameters).then(
(response) => response != null
? new Response(
convertList(response.body, (result) => Bucket.fromJSON(result)),
response.statusCode,
response.headers)
: null);
}

@override
Expand All @@ -51,10 +50,11 @@ class BucketAPIService extends APIService implements BucketService {
@override
Future<Bucket?> update(Bucket bucket) {
return client
.post('/projects/${bucket.projectId}/buckets/${bucket.id}', body: bucket.toJSON())
.post('/projects/${bucket.projectId}/buckets/${bucket.id}',
body: bucket.toJSON())
.then((response) {
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
if (response == null) return null;
return Bucket.fromJSON(response.body);
});
}
}
}
137 changes: 67 additions & 70 deletions lib/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:vikunja_app/global.dart';

import '../main.dart';


class Client {
GlobalKey<ScaffoldMessengerState>? global_scaffold_key;
final JsonDecoder _decoder = new JsonDecoder();
Expand All @@ -26,8 +25,6 @@ class Client {

String? post_body;



bool operator ==(dynamic otherClient) {
return otherClient._token == _token;
}
Expand All @@ -40,15 +37,14 @@ class Client {
void reload_ignore_certs(bool? val) {
ignoreCertificates = val ?? false;
HttpOverrides.global = new IgnoreCertHttpOverrides(ignoreCertificates);
if(global_scaffold_key == null || global_scaffold_key!.currentContext == null) return;
VikunjaGlobal
.of(global_scaffold_key!.currentContext!)
if (global_scaffold_key == null ||
global_scaffold_key!.currentContext == null) return;
VikunjaGlobal.of(global_scaffold_key!.currentContext!)
.settingsManager
.setIgnoreCertificates(ignoreCertificates);
}

get _headers =>
{
get _headers => {
'Authorization': _token != '' ? 'Bearer $_token' : '',
'Content-Type': 'application/json',
'User-Agent': 'Vikunja Mobile App'
Expand All @@ -60,20 +56,15 @@ class Client {
int get hashCode => _token.hashCode;

void configure({String? token, String? base, bool? authenticated}) {
if (token != null)
_token = token;
if (token != null) _token = token;
if (base != null) {
base = base.replaceAll(" ", "");
if(base.endsWith("/"))
base = base.substring(0,base.length-1);
if (base.endsWith("/")) base = base.substring(0, base.length - 1);
_base = base.endsWith('/api/v1') ? base : '$base/api/v1';
}
if (authenticated != null)
this.authenticated = authenticated;

if (authenticated != null) this.authenticated = authenticated;
}


void reset() {
_token = _base = '';
authenticated = false;
Expand All @@ -85,54 +76,61 @@ class Client {
// why are we doing it like this? because Uri doesnt have setters. wtf.

uri = Uri(
scheme: uri.scheme,
scheme: uri.scheme,
userInfo: uri.userInfo,
host: uri.host,
port: uri.port,
path: uri.path,
//queryParameters: {...uri.queryParameters, ...?queryParameters},
queryParameters: queryParameters,
fragment: uri.fragment
);
fragment: uri.fragment);

return http.get(uri, headers: _headers)
.then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.get(uri, headers: _headers)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Future<Response?> delete(String url) {
return http.delete(
'${this.base}$url'.toUri()!,
headers: _headers,
).then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.delete(
'${this.base}$url'.toUri()!,
headers: _headers,
)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Future<Response?> post(String url, {dynamic body}) {
return http.post(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.post(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Future<Response?> put(String url, {dynamic body}) {
return http.put(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.put(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Response? _handleError(Object? e, StackTrace? st) {
if(global_scaffold_key == null) return null;
if (global_scaffold_key == null) return null;
SnackBar snackBar = SnackBar(
content: Text("Error on request: " + e.toString()),
action: SnackBarAction(label: "Clear", onPressed: () => global_scaffold_key!.currentState?.clearSnackBars()),);
action: SnackBarAction(
label: "Clear",
onPressed: () => global_scaffold_key!.currentState?.clearSnackBars()),
);
global_scaffold_key!.currentState?.showSnackBar(snackBar);
return null;
}
Expand All @@ -145,39 +143,38 @@ class Client {
return map;
}


Error? _handleResponseErrors(http.Response response) {
if (response.statusCode < 200 ||
response.statusCode >= 400) {
if (response.statusCode < 200 || response.statusCode >= 400) {
Map<String, dynamic> error;
error = _decoder.convert(response.body);


final SnackBar snackBar = SnackBar(
content: Text(
"Error code " + response.statusCode.toString() + " received."),
action: globalNavigatorKey.currentContext == null ? null : SnackBarAction(
label: ("Details"),
onPressed: () {
showDialog(
context: globalNavigatorKey.currentContext!,
builder: (BuildContext context) =>
AlertDialog(
title: Text("Error ${response.statusCode}"),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text("Message: ${error["message"]}", textAlign: TextAlign.start,),
Text("Url: ${response.request!.url.toString()}"),
],
)
)
);
},
),
content:
Text("Error code " + response.statusCode.toString() + " received."),
action: globalNavigatorKey.currentContext == null
? null
: SnackBarAction(
label: ("Details"),
onPressed: () {
showDialog(
context: globalNavigatorKey.currentContext!,
builder: (BuildContext context) => AlertDialog(
title: Text("Error ${response.statusCode}"),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Message: ${error["message"]}",
textAlign: TextAlign.start,
),
Text("Url: ${response.request!.url.toString()}"),
],
)));
},
),
);
if(global_scaffold_key != null && showSnackBar)
if (global_scaffold_key != null && showSnackBar)
global_scaffold_key!.currentState?.showSnackBar(snackBar);
else
print("error on request: ${error["message"]}");
Expand Down
17 changes: 8 additions & 9 deletions lib/api/label_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ class LabelTaskAPIService extends APIService implements LabelTaskService {
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
});
}

@override
Future<Label?> delete(LabelTask lt) async {
return client
.delete('/tasks/${lt.task!.id}/labels/${lt.label.id}')
.then((response) {
if (response == null) return null;
return Label.fromJson(response.body);
});
if (response == null) return null;
return Label.fromJson(response.body);
});
}

@override
Future<List<Label>?> getAll(LabelTask lt, {String? query}) async {
String? params =
query == null ? null : '?s=' + Uri.encodeQueryComponent(query);

return client.get('/tasks/${lt.task!.id}/labels$params').then(
(label) {
if (label == null) return null;
return convertList(label, (result) => Label.fromJson(result));
});
return client.get('/tasks/${lt.task!.id}/labels$params').then((label) {
if (label == null) return null;
return convertList(label, (result) => Label.fromJson(result));
});
}
}
11 changes: 5 additions & 6 deletions lib/api/label_task_bulk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ class LabelTaskBulkAPIService extends APIService

@override
Future<List<Label>?> update(Task task, List<Label>? labels) {
if(labels == null)
labels = [];
if (labels == null) labels = [];
return client
.post('/tasks/${task.id}/labels/bulk',
body: LabelTaskBulk(labels: labels).toJSON())
.then((response) {
if (response == null) return null;
return convertList(
response.body['labels'], (result) => Label.fromJson(result));
});
if (response == null) return null;
return convertList(
response.body['labels'], (result) => Label.fromJson(result));
});
}
}
Loading

0 comments on commit 056b2d7

Please sign in to comment.