From 056b2d72c9bff722251e179473504e3d56345bc1 Mon Sep 17 00:00:00 2001 From: Denys Vitali Date: Fri, 5 Apr 2024 22:36:56 +0200 Subject: [PATCH] chore: format code with dart format (#71) 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. --- .github/workflows/flutter-format.yml | 20 ++ lib/api/bucket_implementation.dart | 34 ++-- lib/api/client.dart | 137 ++++++------- lib/api/label_task.dart | 17 +- lib/api/label_task_bulk.dart | 11 +- lib/api/labels.dart | 49 ++--- lib/api/list_implementation.dart | 63 +++--- lib/api/namespace_implementation.dart | 4 +- lib/api/project.dart | 16 +- lib/api/server_implementation.dart | 3 +- lib/api/task_implementation.dart | 93 +++++---- lib/api/user_implementation.dart | 21 +- lib/api/version_check.dart | 4 +- lib/components/AddDialog.dart | 53 +++-- lib/components/BucketLimitDialog.dart | 9 +- lib/components/BucketTaskCard.dart | 132 +++++++----- lib/components/KanbanWidget.dart | 51 +++-- lib/components/SliverBucketList.dart | 26 ++- .../SliverBucketPersistentHeader.dart | 17 +- lib/components/TaskBottomSheet.dart | 190 ++++++++++-------- lib/components/TaskTile.dart | 5 +- lib/components/date_extension.dart | 1 + lib/components/datetimePicker.dart | 35 ++-- lib/global.dart | 55 ++--- lib/main.dart | 108 +++++----- lib/managers/notifications.dart | 91 ++++----- lib/models/bucket.dart | 24 +-- lib/models/label.dart | 4 +- lib/models/labelTask.dart | 3 +- lib/models/list.dart | 8 +- lib/models/project.dart | 79 ++++---- lib/models/server.dart | 5 +- lib/models/task.dart | 4 +- lib/models/taskAttachment.dart | 27 ++- lib/models/user.dart | 48 +++-- lib/pages/home.dart | 1 - lib/pages/landing_page.dart | 128 ++++++------ lib/pages/list/list.dart | 29 ++- lib/pages/list/list_edit.dart | 25 ++- lib/pages/list/task_edit.dart | 87 ++++---- lib/pages/namespace/namespace.dart | 7 +- lib/pages/namespace/namespace_edit.dart | 6 +- lib/pages/namespace/overview.dart | 51 ++--- lib/pages/project/overview.dart | 50 +++-- lib/pages/project/project.dart | 1 + lib/pages/project/project_edit.dart | 44 ++-- lib/pages/project/project_task_list.dart | 182 +++++++++-------- lib/pages/settings.dart | 90 +++++---- lib/pages/user/login.dart | 146 +++++++------- lib/pages/user/login_webview.dart | 70 +++---- lib/pages/user/register.dart | 7 +- lib/service/mocked_services.dart | 8 +- lib/service/services.dart | 78 +++---- lib/stores/list_store.dart | 181 ++++++++++------- lib/stores/project_store.dart | 165 +++++++++------ lib/theme/button.dart | 6 +- lib/theme/buttonText.dart | 4 +- lib/theme/constants.dart | 2 +- lib/theme/theme.dart | 18 +- lib/utils/calculate_item_position.dart | 2 +- lib/utils/checkboxes_in_text.dart | 1 - lib/utils/misc.dart | 19 +- lib/utils/priority.dart | 3 +- lib/utils/repeat_after_parse.dart | 2 +- test/parse_label_color.dart | 14 +- test/task_json_decode_test.dart | 38 ++-- 66 files changed, 1563 insertions(+), 1349 deletions(-) create mode 100644 .github/workflows/flutter-format.yml diff --git a/.github/workflows/flutter-format.yml b/.github/workflows/flutter-format.yml new file mode 100644 index 0000000..77225b6 --- /dev/null +++ b/.github/workflows/flutter-format.yml @@ -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 . \ No newline at end of file diff --git a/lib/api/bucket_implementation.dart b/lib/api/bucket_implementation.dart index df6a7f8..8b32254 100644 --- a/lib/api/bucket_implementation.dart +++ b/lib/api/bucket_implementation.dart @@ -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 @@ -35,13 +34,13 @@ class BucketAPIService extends APIService implements BucketService { @override Future getAllByList(int projectId, [Map>? 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 @@ -51,10 +50,11 @@ class BucketAPIService extends APIService implements BucketService { @override Future 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); + }); } -} \ No newline at end of file +} diff --git a/lib/api/client.dart b/lib/api/client.dart index dcd6c1d..bf8c66c 100644 --- a/lib/api/client.dart +++ b/lib/api/client.dart @@ -10,7 +10,6 @@ import 'package:vikunja_app/global.dart'; import '../main.dart'; - class Client { GlobalKey? global_scaffold_key; final JsonDecoder _decoder = new JsonDecoder(); @@ -26,8 +25,6 @@ class Client { String? post_body; - - bool operator ==(dynamic otherClient) { return otherClient._token == _token; } @@ -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' @@ -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; @@ -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 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 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 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; } @@ -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 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"]}"); diff --git a/lib/api/label_task.dart b/lib/api/label_task.dart index dbd134e..78a2823 100644 --- a/lib/api/label_task.dart +++ b/lib/api/label_task.dart @@ -14,7 +14,7 @@ class LabelTaskAPIService extends APIService implements LabelTaskService { .then((response) { if (response == null) return null; return Label.fromJson(response.body); - }); + }); } @override @@ -22,9 +22,9 @@ class LabelTaskAPIService extends APIService implements LabelTaskService { 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 @@ -32,10 +32,9 @@ class LabelTaskAPIService extends APIService implements LabelTaskService { 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)); + }); } } diff --git a/lib/api/label_task_bulk.dart b/lib/api/label_task_bulk.dart index 982d53b..fd7267a 100644 --- a/lib/api/label_task_bulk.dart +++ b/lib/api/label_task_bulk.dart @@ -11,15 +11,14 @@ class LabelTaskBulkAPIService extends APIService @override Future?> update(Task task, List