From 011113d72b67809a6229e4a44c6fef208eb95b0b Mon Sep 17 00:00:00 2001 From: Varakh Date: Thu, 23 Jun 2022 00:44:08 +0200 Subject: [PATCH] Reformat code with latest Flutter 3 linting --- lib/core/manager/dialog_manager.dart | 3 +- lib/core/models/rest/apikey.dart | 6 +- lib/core/models/rest/apikeys.dart | 3 +- lib/core/models/rest/apikeys_response.dart | 3 +- lib/core/models/rest/config_response.dart | 3 +- .../models/rest/create_apikey_response.dart | 3 +- lib/core/models/rest/history.dart | 3 +- lib/core/models/rest/history_item.dart | 3 +- .../models/rest/history_multipaste_item.dart | 3 +- .../rest/history_multipaste_item_entry.dart | 3 +- lib/core/models/rest/history_response.dart | 3 +- lib/core/models/rest/rest_error.dart | 3 +- lib/core/models/rest/uploaded.dart | 3 +- lib/core/models/rest/uploaded_multi.dart | 3 +- .../models/rest/uploaded_multi_response.dart | 3 +- lib/core/models/rest/uploaded_response.dart | 3 +- lib/core/models/session.dart | 3 +- lib/core/models/uploaded_paste.dart | 3 +- lib/core/repositories/file_repository.dart | 12 +-- lib/core/repositories/user_repository.dart | 4 +- lib/core/services/api.dart | 51 ++++------- lib/core/services/dialog_service.dart | 18 +--- lib/core/services/file_service.dart | 3 +- lib/core/services/permission_service.dart | 8 +- lib/core/services/user_service.dart | 10 +- lib/core/viewmodels/history_model.dart | 18 ++-- lib/core/viewmodels/login_model.dart | 15 +-- lib/ui/app_router.dart | 3 +- lib/ui/views/base_view.dart | 4 +- lib/ui/views/history_view.dart | 18 ++-- lib/ui/views/login_view.dart | 19 ++-- lib/ui/views/tabbar_anonymous.dart | 3 +- lib/ui/views/tabbar_container_view.dart | 3 +- lib/ui/views/upload_view.dart | 91 ++++++------------- lib/ui/widgets/swipe_navigation.dart | 3 +- 35 files changed, 107 insertions(+), 233 deletions(-) diff --git a/lib/core/manager/dialog_manager.dart b/lib/core/manager/dialog_manager.dart index 5fec7ab..23974d0 100644 --- a/lib/core/manager/dialog_manager.dart +++ b/lib/core/manager/dialog_manager.dart @@ -30,8 +30,7 @@ class _DialogManagerState extends State { void _showDialog(DialogRequest request) { List actions = []; - if (request.buttonTitleDeny != null && - request.buttonTitleDeny!.isNotEmpty) { + if (request.buttonTitleDeny != null && request.buttonTitleDeny!.isNotEmpty) { Widget denyBtn = TextButton( child: Text(request.buttonTitleDeny!), onPressed: () { diff --git a/lib/core/models/rest/apikey.dart b/lib/core/models/rest/apikey.dart index 2386259..0e3d8bf 100644 --- a/lib/core/models/rest/apikey.dart +++ b/lib/core/models/rest/apikey.dart @@ -15,11 +15,7 @@ class ApiKey { final String? comment; - ApiKey( - {required this.key, - required this.created, - required this.accessLevel, - this.comment}); + ApiKey({required this.key, required this.created, required this.accessLevel, this.comment}); // JSON Init factory ApiKey.fromJson(Map json) => _$ApiKeyFromJson(json); diff --git a/lib/core/models/rest/apikeys.dart b/lib/core/models/rest/apikeys.dart index f6b30a5..d8e6191 100644 --- a/lib/core/models/rest/apikeys.dart +++ b/lib/core/models/rest/apikeys.dart @@ -12,8 +12,7 @@ class ApiKeys { ApiKeys({required this.apikeys}); // JSON Init - factory ApiKeys.fromJson(Map json) => - _$ApiKeysFromJson(json); + factory ApiKeys.fromJson(Map json) => _$ApiKeysFromJson(json); // JSON Export Map toJson() => _$ApiKeysToJson(this); diff --git a/lib/core/models/rest/apikeys_response.dart b/lib/core/models/rest/apikeys_response.dart index a2bd8f8..138642a 100644 --- a/lib/core/models/rest/apikeys_response.dart +++ b/lib/core/models/rest/apikeys_response.dart @@ -15,8 +15,7 @@ class ApiKeysResponse { ApiKeysResponse({required this.status, required this.data}); // JSON Init - factory ApiKeysResponse.fromJson(Map json) => - _$ApiKeysResponseFromJson(json); + factory ApiKeysResponse.fromJson(Map json) => _$ApiKeysResponseFromJson(json); // JSON Export Map toJson() => _$ApiKeysResponseToJson(this); diff --git a/lib/core/models/rest/config_response.dart b/lib/core/models/rest/config_response.dart index d25ac7d..7e26ea0 100644 --- a/lib/core/models/rest/config_response.dart +++ b/lib/core/models/rest/config_response.dart @@ -15,8 +15,7 @@ class ConfigResponse { ConfigResponse({required this.status, required this.data}); // JSON Init - factory ConfigResponse.fromJson(Map json) => - _$ConfigResponseFromJson(json); + factory ConfigResponse.fromJson(Map json) => _$ConfigResponseFromJson(json); // JSON Export Map toJson() => _$ConfigResponseToJson(this); diff --git a/lib/core/models/rest/create_apikey_response.dart b/lib/core/models/rest/create_apikey_response.dart index 55efe99..9614676 100644 --- a/lib/core/models/rest/create_apikey_response.dart +++ b/lib/core/models/rest/create_apikey_response.dart @@ -13,8 +13,7 @@ class CreateApiKeyResponse { CreateApiKeyResponse({required this.status, required this.data}); // JSON Init - factory CreateApiKeyResponse.fromJson(Map json) => - _$CreateApiKeyResponseFromJson(json); + factory CreateApiKeyResponse.fromJson(Map json) => _$CreateApiKeyResponseFromJson(json); // JSON Export Map toJson() => _$CreateApiKeyResponseToJson(this); diff --git a/lib/core/models/rest/history.dart b/lib/core/models/rest/history.dart index 94ec42d..602a290 100644 --- a/lib/core/models/rest/history.dart +++ b/lib/core/models/rest/history.dart @@ -19,8 +19,7 @@ class History { History({required this.items, required this.multipasteItems, this.totalSize}); // JSON Init - factory History.fromJson(Map json) => - _$HistoryFromJson(json); + factory History.fromJson(Map json) => _$HistoryFromJson(json); // JSON Export Map toJson() => _$HistoryToJson(this); diff --git a/lib/core/models/rest/history_item.dart b/lib/core/models/rest/history_item.dart index 54364e1..17744ba 100644 --- a/lib/core/models/rest/history_item.dart +++ b/lib/core/models/rest/history_item.dart @@ -23,8 +23,7 @@ class HistoryItem { this.thumbnail}); // JSON Init - factory HistoryItem.fromJson(Map json) => - _$HistoryItemFromJson(json); + factory HistoryItem.fromJson(Map json) => _$HistoryItemFromJson(json); // JSON Export Map toJson() => _$HistoryItemToJson(this); diff --git a/lib/core/models/rest/history_multipaste_item.dart b/lib/core/models/rest/history_multipaste_item.dart index 1b56dcd..cde11dc 100644 --- a/lib/core/models/rest/history_multipaste_item.dart +++ b/lib/core/models/rest/history_multipaste_item.dart @@ -15,8 +15,7 @@ class HistoryMultipasteItem { HistoryMultipasteItem(this.items, {required this.date, required this.urlId}); // JSON Init - factory HistoryMultipasteItem.fromJson(Map json) => - _$HistoryMultipasteItemFromJson(json); + factory HistoryMultipasteItem.fromJson(Map json) => _$HistoryMultipasteItemFromJson(json); // JSON Export Map toJson() => _$HistoryMultipasteItemToJson(this); diff --git a/lib/core/models/rest/history_multipaste_item_entry.dart b/lib/core/models/rest/history_multipaste_item_entry.dart index fb37fb2..209fb2e 100644 --- a/lib/core/models/rest/history_multipaste_item_entry.dart +++ b/lib/core/models/rest/history_multipaste_item_entry.dart @@ -9,8 +9,7 @@ class HistoryMultipasteItemEntry { HistoryMultipasteItemEntry({required this.id}); // JSON Init - factory HistoryMultipasteItemEntry.fromJson(Map json) => - _$HistoryMultipasteItemEntryFromJson(json); + factory HistoryMultipasteItemEntry.fromJson(Map json) => _$HistoryMultipasteItemEntryFromJson(json); // JSON Export Map toJson() => _$HistoryMultipasteItemEntryToJson(this); diff --git a/lib/core/models/rest/history_response.dart b/lib/core/models/rest/history_response.dart index fa8f904..bfc3548 100644 --- a/lib/core/models/rest/history_response.dart +++ b/lib/core/models/rest/history_response.dart @@ -15,8 +15,7 @@ class HistoryResponse { HistoryResponse({required this.status, required this.data}); // JSON Init - factory HistoryResponse.fromJson(Map json) => - _$HistoryResponseFromJson(json); + factory HistoryResponse.fromJson(Map json) => _$HistoryResponseFromJson(json); // JSON Export Map toJson() => _$HistoryResponseToJson(this); diff --git a/lib/core/models/rest/rest_error.dart b/lib/core/models/rest/rest_error.dart index 6db731c..30b3d6f 100644 --- a/lib/core/models/rest/rest_error.dart +++ b/lib/core/models/rest/rest_error.dart @@ -15,8 +15,7 @@ class RestError { required this.errorId, }); // JSON Init - factory RestError.fromJson(Map json) => - _$RestErrorFromJson(json); + factory RestError.fromJson(Map json) => _$RestErrorFromJson(json); // JSON Export Map toJson() => _$RestErrorToJson(this); diff --git a/lib/core/models/rest/uploaded.dart b/lib/core/models/rest/uploaded.dart index 28f0a6a..7405970 100644 --- a/lib/core/models/rest/uploaded.dart +++ b/lib/core/models/rest/uploaded.dart @@ -13,8 +13,7 @@ class Uploaded { Uploaded({required this.ids, required this.urls}); // JSON Init - factory Uploaded.fromJson(Map json) => - _$UploadedFromJson(json); + factory Uploaded.fromJson(Map json) => _$UploadedFromJson(json); // JSON Export Map toJson() => _$UploadedToJson(this); diff --git a/lib/core/models/rest/uploaded_multi.dart b/lib/core/models/rest/uploaded_multi.dart index f404269..6339bb8 100644 --- a/lib/core/models/rest/uploaded_multi.dart +++ b/lib/core/models/rest/uploaded_multi.dart @@ -13,8 +13,7 @@ class UploadedMulti { UploadedMulti({required this.url, required this.urlId}); // JSON Init - factory UploadedMulti.fromJson(Map json) => - _$UploadedMultiFromJson(json); + factory UploadedMulti.fromJson(Map json) => _$UploadedMultiFromJson(json); // JSON Export Map toJson() => _$UploadedMultiToJson(this); diff --git a/lib/core/models/rest/uploaded_multi_response.dart b/lib/core/models/rest/uploaded_multi_response.dart index 51a03a2..b6de81f 100644 --- a/lib/core/models/rest/uploaded_multi_response.dart +++ b/lib/core/models/rest/uploaded_multi_response.dart @@ -15,8 +15,7 @@ class UploadedMultiResponse { UploadedMultiResponse({required this.status, required this.data}); // JSON Init - factory UploadedMultiResponse.fromJson(Map json) => - _$UploadedMultiResponseFromJson(json); + factory UploadedMultiResponse.fromJson(Map json) => _$UploadedMultiResponseFromJson(json); // JSON Export Map toJson() => _$UploadedMultiResponseToJson(this); diff --git a/lib/core/models/rest/uploaded_response.dart b/lib/core/models/rest/uploaded_response.dart index 707373f..9ed84b1 100644 --- a/lib/core/models/rest/uploaded_response.dart +++ b/lib/core/models/rest/uploaded_response.dart @@ -15,8 +15,7 @@ class UploadedResponse { UploadedResponse({required this.status, required this.data}); // JSON Init - factory UploadedResponse.fromJson(Map json) => - _$UploadedResponseFromJson(json); + factory UploadedResponse.fromJson(Map json) => _$UploadedResponseFromJson(json); // JSON Export Map toJson() => _$UploadedResponseToJson(this); diff --git a/lib/core/models/session.dart b/lib/core/models/session.dart index 4d07ac5..a2725a8 100644 --- a/lib/core/models/session.dart +++ b/lib/core/models/session.dart @@ -13,8 +13,7 @@ class Session { : url = '', apiKey = ''; - factory Session.fromJson(Map json) => - _$SessionFromJson(json); + factory Session.fromJson(Map json) => _$SessionFromJson(json); Map toJson() => _$SessionToJson(this); } diff --git a/lib/core/models/uploaded_paste.dart b/lib/core/models/uploaded_paste.dart index 7db14b6..d209696 100644 --- a/lib/core/models/uploaded_paste.dart +++ b/lib/core/models/uploaded_paste.dart @@ -26,8 +26,7 @@ class UploadedPaste { this.items}); // JSON Init - factory UploadedPaste.fromJson(Map json) => - _$UploadedPasteFromJson(json); + factory UploadedPaste.fromJson(Map json) => _$UploadedPasteFromJson(json); // JSON Export Map toJson() => _$UploadedPasteToJson(this); diff --git a/lib/core/repositories/file_repository.dart b/lib/core/repositories/file_repository.dart index 8196fa8..be94fef 100644 --- a/lib/core/repositories/file_repository.dart +++ b/lib/core/repositories/file_repository.dart @@ -33,10 +33,8 @@ class FileRepository { return response; } - Future postUpload( - List? files, Map? additionalFiles) async { - var response = await _api.post('/file/upload', - files: files, additionalFiles: additionalFiles); + Future postUpload(List? files, Map? additionalFiles) async { + var response = await _api.post('/file/upload', files: files, additionalFiles: additionalFiles); return UploadedResponse.fromJson(json.decode(response.body)); } @@ -44,12 +42,10 @@ class FileRepository { Map multiPasteIds = Map(); ids.forEach((element) { - multiPasteIds.putIfAbsent( - "ids[${ids.indexOf(element) + 1}]", () => element); + multiPasteIds.putIfAbsent("ids[${ids.indexOf(element) + 1}]", () => element); }); - var response = - await _api.post('/file/create_multipaste', fields: multiPasteIds); + var response = await _api.post('/file/create_multipaste', fields: multiPasteIds); return UploadedMultiResponse.fromJson(json.decode(response.body)); } } diff --git a/lib/core/repositories/user_repository.dart b/lib/core/repositories/user_repository.dart index bb74855..5fe8fd0 100644 --- a/lib/core/repositories/user_repository.dart +++ b/lib/core/repositories/user_repository.dart @@ -8,8 +8,8 @@ import '../services/api.dart'; class UserRepository { Api _api = locator(); - Future postApiKey(String url, String username, - String password, String accessLevel, String comment) async { + Future postApiKey( + String url, String username, String password, String accessLevel, String comment) async { _api.setUrl(url); var fields = Map.fromEntries([ diff --git a/lib/core/services/api.dart b/lib/core/services/api.dart index 0bdb16a..53b80ac 100644 --- a/lib/core/services/api.dart +++ b/lib/core/services/api.dart @@ -24,34 +24,25 @@ class Api implements ApiErrorConverter { String _url = ""; String _apiKey = ""; - Map _headers = { - "Content-Type": _applicationJson, - "Accept": _applicationJson - }; + Map _headers = {"Content-Type": _applicationJson, "Accept": _applicationJson}; Duration _timeout = Duration(seconds: Constants.apiRequestTimeoutLimit); Future fetch(String route) async { try { - _logger.d( - "Requesting GET API endpoint '${_url + route}' with headers '$_headers' and maximum timeout '$_timeout'"); - var response = await http - .get(Uri.parse(_url + route), headers: _headers) - .timeout(_timeout); + _logger + .d("Requesting GET API endpoint '${_url + route}' with headers '$_headers' and maximum timeout '$_timeout'"); + var response = await http.get(Uri.parse(_url + route), headers: _headers).timeout(_timeout); handleRestErrors(response); return response; } on TimeoutException { - throw ServiceException( - code: ErrorCode.SOCKET_TIMEOUT, message: _errorTimeout); + throw ServiceException(code: ErrorCode.SOCKET_TIMEOUT, message: _errorTimeout); } on SocketException { - throw ServiceException( - code: ErrorCode.SOCKET_ERROR, message: _errorNoConnection); + throw ServiceException(code: ErrorCode.SOCKET_ERROR, message: _errorNoConnection); } } Future post(String route, - {Map? fields, - List? files, - Map? additionalFiles}) async { + {Map? fields, List? files, Map? additionalFiles}) async { try { var uri = Uri.parse(_url + route); var request = http.MultipartRequest('POST', uri) @@ -68,34 +59,27 @@ class Api implements ApiErrorConverter { if (files != null && files.isNotEmpty) { files.forEach((element) async { - request.files.add(await http.MultipartFile.fromPath( - 'file[${files.indexOf(element) + 1}]', element.path)); + request.files.add(await http.MultipartFile.fromPath('file[${files.indexOf(element) + 1}]', element.path)); }); } if (additionalFiles != null && additionalFiles.length > 0) { List keys = additionalFiles.keys.toList(); additionalFiles.forEach((key, value) { - var index = files != null - ? files.length + keys.indexOf(key) + 1 - : keys.indexOf(key) + 1; - request.files.add(http.MultipartFile.fromString('file[$index]', value, - filename: key)); + var index = files != null ? files.length + keys.indexOf(key) + 1 : keys.indexOf(key) + 1; + request.files.add(http.MultipartFile.fromString('file[$index]', value, filename: key)); }); } - _logger.d( - "Requesting POST API endpoint '${uri.toString()}' and ${request.files.length} files"); + _logger.d("Requesting POST API endpoint '${uri.toString()}' and ${request.files.length} files"); var multiResponse = await request.send(); var response = await http.Response.fromStream(multiResponse); handleRestErrors(response); return response; } on TimeoutException { - throw ServiceException( - code: ErrorCode.SOCKET_TIMEOUT, message: _errorTimeout); + throw ServiceException(code: ErrorCode.SOCKET_TIMEOUT, message: _errorTimeout); } on SocketException { - throw ServiceException( - code: ErrorCode.SOCKET_ERROR, message: _errorNoConnection); + throw ServiceException(code: ErrorCode.SOCKET_ERROR, message: _errorNoConnection); } } @@ -123,17 +107,14 @@ class Api implements ApiErrorConverter { /// have a json decoded object. Replace this with a custom /// conversion method by overwriting the interface if needed void handleRestErrors(http.Response response) { - if (response.statusCode != HttpStatus.ok && - response.statusCode != HttpStatus.noContent) { + if (response.statusCode != HttpStatus.ok && response.statusCode != HttpStatus.noContent) { if (response.headers.containsKey(HttpHeaders.contentTypeHeader)) { - ContentType responseContentType = - ContentType.parse(response.headers[HttpHeaders.contentTypeHeader]!); + ContentType responseContentType = ContentType.parse(response.headers[HttpHeaders.contentTypeHeader]!); if (ContentType.json.primaryType == responseContentType.primaryType && ContentType.json.subType == responseContentType.subType) { var parsedBody = convert(response); - throw new RestServiceException(response.statusCode, - responseBody: parsedBody); + throw new RestServiceException(response.statusCode, responseBody: parsedBody); } } diff --git a/lib/core/services/dialog_service.dart b/lib/core/services/dialog_service.dart index 2b6788e..e1fcd1a 100644 --- a/lib/core/services/dialog_service.dart +++ b/lib/core/services/dialog_service.dart @@ -27,28 +27,20 @@ class DialogService { title: title, description: description, buttonTitleAccept: - buttonTitleAccept == null || buttonTitleAccept.isEmpty - ? translate('dialog.confirm') - : buttonTitleAccept)); + buttonTitleAccept == null || buttonTitleAccept.isEmpty ? translate('dialog.confirm') : buttonTitleAccept)); return _dialogCompleter!.future; } Future showConfirmationDialog( - {String? title, - String? description, - String? buttonTitleAccept, - String? buttonTitleDeny}) { + {String? title, String? description, String? buttonTitleAccept, String? buttonTitleDeny}) { _dialogCompleter = Completer(); _showDialogListener(DialogRequest( title: title, description: description, buttonTitleAccept: - buttonTitleAccept == null || buttonTitleAccept.isEmpty - ? translate('dialog.confirm') - : buttonTitleAccept, - buttonTitleDeny: buttonTitleDeny == null || buttonTitleDeny.isEmpty - ? translate('dialog.cancel') - : buttonTitleDeny)); + buttonTitleAccept == null || buttonTitleAccept.isEmpty ? translate('dialog.confirm') : buttonTitleAccept, + buttonTitleDeny: + buttonTitleDeny == null || buttonTitleDeny.isEmpty ? translate('dialog.cancel') : buttonTitleDeny)); return _dialogCompleter!.future; } diff --git a/lib/core/services/file_service.dart b/lib/core/services/file_service.dart index 8ce822f..fd4a7e2 100644 --- a/lib/core/services/file_service.dart +++ b/lib/core/services/file_service.dart @@ -23,8 +23,7 @@ class FileService { return await _fileRepository.postDelete(id); } - Future uploadPaste( - List? files, Map? additionalFiles) async { + Future uploadPaste(List? files, Map? additionalFiles) async { return await _fileRepository.postUpload(files, additionalFiles); } diff --git a/lib/core/services/permission_service.dart b/lib/core/services/permission_service.dart index 548331c..5f68e79 100644 --- a/lib/core/services/permission_service.dart +++ b/lib/core/services/permission_service.dart @@ -57,8 +57,7 @@ class PermissionService extends StoppableService { return; } - var ignoredDialog = - await _storageService.hasStoragePermissionDialogIgnored(); + var ignoredDialog = await _storageService.hasStoragePermissionDialogIgnored(); if (ignoredDialog) { _logger.d('Permanently ignored permission request, skipping'); @@ -105,9 +104,8 @@ class PermissionService extends StoppableService { super.start(); await checkEnabledAndPermission(); - _serviceCheckTimer = Timer.periodic( - Duration(milliseconds: Constants.mediaPermissionCheckInterval), - (_serviceTimer) async { + _serviceCheckTimer = + Timer.periodic(Duration(milliseconds: Constants.mediaPermissionCheckInterval), (_serviceTimer) async { if (!super.serviceStopped) { await checkEnabledAndPermission(); } else { diff --git a/lib/core/services/user_service.dart b/lib/core/services/user_service.dart index 36bd78c..e4ea69c 100644 --- a/lib/core/services/user_service.dart +++ b/lib/core/services/user_service.dart @@ -12,10 +12,9 @@ class UserService { final FileService _fileService = locator(); final UserRepository _userRepository = locator(); - Future createApiKey(String url, String username, - String password, String accessLevel, String comment) async { - return await _userRepository.postApiKey( - url, username, password, accessLevel, comment); + Future createApiKey( + String url, String username, String password, String accessLevel, String comment) async { + return await _userRepository.postApiKey(url, username, password, accessLevel, comment); } Future getApiKeys() async { @@ -27,8 +26,7 @@ class UserService { try { await _fileService.getHistory(); } on ServiceException catch (e) { - throw new ServiceException( - code: ErrorCode.INVALID_API_KEY, message: e.message); + throw new ServiceException(code: ErrorCode.INVALID_API_KEY, message: e.message); } } } diff --git a/lib/core/viewmodels/history_model.dart b/lib/core/viewmodels/history_model.dart index 6a2bd17..ced0e2c 100644 --- a/lib/core/viewmodels/history_model.dart +++ b/lib/core/viewmodels/history_model.dart @@ -34,8 +34,7 @@ class HistoryModel extends BaseModel { String? errorMessage; void init() { - _refreshTriggerSubscription = - _refreshService.refreshEventController.stream.listen((event) { + _refreshTriggerSubscription = _refreshService.refreshEventController.stream.listen((event) { if (event == RefreshEvent.RefreshHistory) { _logger.d('History needs a refresh'); getHistory(); @@ -55,8 +54,7 @@ class HistoryModel extends BaseModel { pastes.add( UploadedPaste( id: key, - date: - DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch), + date: DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch), filename: value.filename, filesize: int.parse(value.filesize), hash: value.hash, @@ -92,11 +90,9 @@ class HistoryModel extends BaseModel { e.responseBody is RestError && e.responseBody.message != null) { if (e.statusCode == HttpStatus.badRequest) { - errorMessage = translate('api.bad_request', - args: {'reason': e.responseBody.message}); + errorMessage = translate('api.bad_request', args: {'reason': e.responseBody.message}); } else { - errorMessage = translate('api.general_rest_error_payload', - args: {'message': e.responseBody.message}); + errorMessage = translate('api.general_rest_error_payload', args: {'message': e.responseBody.message}); } } else { errorMessage = translate('api.general_rest_error'); @@ -119,8 +115,7 @@ class HistoryModel extends BaseModel { Future deletePaste(String id) async { DialogResponse res = await _dialogService.showConfirmationDialog( title: translate('history.delete_dialog.title'), - description: - translate('history.delete_dialog.description', args: {'id': id}), + description: translate('history.delete_dialog.description', args: {'id': id}), buttonTitleAccept: translate('history.delete_dialog.accept'), buttonTitleDeny: translate('history.delete_dialog.deny')); @@ -144,8 +139,7 @@ class HistoryModel extends BaseModel { e.statusCode != HttpStatus.forbidden && e.responseBody is RestError && e.responseBody.message != null) { - errorMessage = translate('api.general_rest_error_payload', - args: {'message': e.responseBody.message}); + errorMessage = translate('api.general_rest_error_payload', args: {'message': e.responseBody.message}); } else { errorMessage = translate('api.general_rest_error'); } diff --git a/lib/core/viewmodels/login_model.dart b/lib/core/viewmodels/login_model.dart index 8249a2f..81dde0b 100644 --- a/lib/core/viewmodels/login_model.dart +++ b/lib/core/viewmodels/login_model.dart @@ -117,19 +117,14 @@ class LoginModel extends BaseModel { try { if (useCredentialsLogin) { CreateApiKeyResponse apiKeyResponse = await _userService.createApiKey( - url, - username, - password, - 'apikey', - 'fbmobile-${new DateTime.now().millisecondsSinceEpoch}'); + url, username, password, 'apikey', 'fbmobile-${new DateTime.now().millisecondsSinceEpoch}'); var newKey = apiKeyResponse.data['new_key']; if (newKey != null) { success = await _sessionService.login(url, newKey); } else { throw new ServiceException( - code: ErrorCode.INVALID_API_KEY, - message: translate('login.errors.invalid_api_key')); + code: ErrorCode.INVALID_API_KEY, message: translate('login.errors.invalid_api_key')); } } else { _sessionService.setApiConfig(url, apiKey); @@ -141,15 +136,13 @@ class LoginModel extends BaseModel { if (e is RestServiceException) { if (e.statusCode == HttpStatus.unauthorized) { errorMessage = translate('login.errors.wrong_credentials'); - } else if (e.statusCode != HttpStatus.unauthorized && - e.statusCode == HttpStatus.forbidden) { + } else if (e.statusCode != HttpStatus.unauthorized && e.statusCode == HttpStatus.forbidden) { errorMessage = translate('login.errors.forbidden'); } else if (e.statusCode == HttpStatus.notFound) { errorMessage = translate('api.incompatible_error_not_found'); } if (e.statusCode == HttpStatus.badRequest) { - errorMessage = translate('api.bad_request', - args: {'reason': e.responseBody.message}); + errorMessage = translate('api.bad_request', args: {'reason': e.responseBody.message}); } else { errorMessage = translate('api.general_rest_error'); } diff --git a/lib/ui/app_router.dart b/lib/ui/app_router.dart index aeb4864..4da33d7 100644 --- a/lib/ui/app_router.dart +++ b/lib/ui/app_router.dart @@ -27,8 +27,7 @@ class AppRouter { return MaterialPageRoute( builder: (_) => Scaffold( body: Center( - child: Text(translate('dev.no_route', - args: {'route': settings.name})), + child: Text(translate('dev.no_route', args: {'route': settings.name})), ), )); } diff --git a/lib/ui/views/base_view.dart b/lib/ui/views/base_view.dart index 9bd523f..c4ba15a 100644 --- a/lib/ui/views/base_view.dart +++ b/lib/ui/views/base_view.dart @@ -31,9 +31,7 @@ class _BaseViewState extends State> { @override Widget build(BuildContext context) { - return ChangeNotifierProvider( - create: (context) => model, - child: Consumer(builder: widget.builder!)); + return ChangeNotifierProvider(create: (context) => model, child: Consumer(builder: widget.builder!)); } @override diff --git a/lib/ui/views/history_view.dart b/lib/ui/views/history_view.dart index f6ac554..315bbe7 100644 --- a/lib/ui/views/history_view.dart +++ b/lib/ui/views/history_view.dart @@ -42,8 +42,7 @@ class HistoryView extends StatelessWidget { ? Container( padding: EdgeInsets.all(0), child: RefreshIndicator( - onRefresh: () async => await model.getHistory(), - child: _renderItems(model, url, context))) + onRefresh: () async => await model.getHistory(), child: _renderItems(model, url, context))) : Container( padding: EdgeInsets.all(25), child: CenteredErrorRow( @@ -63,8 +62,7 @@ class HistoryView extends StatelessWidget { var openInBrowserButton = _renderOpenInBrowser(model, fullPasteUrl); var dateWidget = ListTile( - title: Text( - FormatterUtil.formatEpoch(paste.date!.millisecondsSinceEpoch)), + title: Text(FormatterUtil.formatEpoch(paste.date!.millisecondsSinceEpoch)), subtitle: Text(translate('history.date')), ); @@ -76,8 +74,7 @@ class HistoryView extends StatelessWidget { var copyWidget = ListTile( title: Text(translate('history.copy_link.description')), trailing: IconButton( - icon: Icon(Icons.copy, - color: blueColor, textDirection: TextDirection.ltr), + icon: Icon(Icons.copy, color: blueColor, textDirection: TextDirection.ltr), onPressed: () { FlutterClipboard.copy(fullPasteUrl).then((value) { final snackBar = SnackBar( @@ -168,14 +165,12 @@ class HistoryView extends StatelessWidget { trailing: Wrap(children: [ openInBrowserButton, IconButton( - icon: Icon(Icons.share, - color: blueColor, textDirection: TextDirection.ltr), + icon: Icon(Icons.share, color: blueColor, textDirection: TextDirection.ltr), onPressed: () async { await Share.share(fullPasteUrl); }) ]), - subtitle: Text(!paste.isMulti! ? paste.filename! : '', - style: TextStyle(fontStyle: FontStyle.italic)), + subtitle: Text(!paste.isMulti! ? paste.filename! : '', style: TextStyle(fontStyle: FontStyle.italic)), ), )); }); @@ -196,8 +191,7 @@ class HistoryView extends StatelessWidget { Widget _renderOpenInBrowser(HistoryModel model, String url) { return IconButton( - icon: Icon(Icons.open_in_new, - color: blueColor, textDirection: TextDirection.ltr), + icon: Icon(Icons.open_in_new, color: blueColor, textDirection: TextDirection.ltr), onPressed: () { return model.openLink(url); }); diff --git a/lib/ui/views/login_view.dart b/lib/ui/views/login_view.dart index 9004545..b075a56 100644 --- a/lib/ui/views/login_view.dart +++ b/lib/ui/views/login_view.dart @@ -59,18 +59,13 @@ class LoginView extends StatelessWidget { child: Icon(Icons.help, color: buttonBackgroundColor), onTap: () { _dialogService.showDialog( - title: translate( - 'login.compatibility_dialog.title'), - description: translate( - 'login.compatibility_dialog.body')); + title: translate('login.compatibility_dialog.title'), + description: translate('login.compatibility_dialog.body')); }, ), InkWell( - child: Icon( - model.useCredentialsLogin - ? Icons.person_outline - : Icons.vpn_key, - color: blueColor), + child: + Icon(model.useCredentialsLogin ? Icons.person_outline : Icons.vpn_key, color: blueColor), onTap: () { model.toggleLoginMethod(); }, @@ -90,13 +85,11 @@ class LoginView extends StatelessWidget { apiKeyController: model.apiKeyController), UIHelper.verticalSpaceMedium(), ElevatedButton( - child: Text(translate('login.button'), - style: TextStyle(color: buttonForegroundColor)), + child: Text(translate('login.button'), style: TextStyle(color: buttonForegroundColor)), onPressed: () async { var loginSuccess = await model.login(); if (loginSuccess) { - _navigationService - .navigateAndReplaceTo(HomeView.routeName); + _navigationService.navigateAndReplaceTo(HomeView.routeName); } }, ) diff --git a/lib/ui/views/tabbar_anonymous.dart b/lib/ui/views/tabbar_anonymous.dart index c461dbb..c4b68c4 100644 --- a/lib/ui/views/tabbar_anonymous.dart +++ b/lib/ui/views/tabbar_anonymous.dart @@ -9,8 +9,7 @@ class AnonymousTabBarView extends StatefulWidget { AnonymousTabBarState createState() => AnonymousTabBarState(); } -class AnonymousTabBarState extends State - with SingleTickerProviderStateMixin { +class AnonymousTabBarState extends State with SingleTickerProviderStateMixin { TabController? _tabController; int _currentTabIndex = 0; diff --git a/lib/ui/views/tabbar_container_view.dart b/lib/ui/views/tabbar_container_view.dart index 66ca2f6..f9dead3 100644 --- a/lib/ui/views/tabbar_container_view.dart +++ b/lib/ui/views/tabbar_container_view.dart @@ -9,8 +9,7 @@ class TabBarContainerView extends StatelessWidget { @override Widget build(BuildContext context) { Session? currentSession = Provider.of(context); - bool isAuthenticated = - currentSession != null ? currentSession.apiKey.isNotEmpty : false; + bool isAuthenticated = currentSession != null ? currentSession.apiKey.isNotEmpty : false; if (isAuthenticated) { return AuthenticatedTabBarView(); diff --git a/lib/ui/views/upload_view.dart b/lib/ui/views/upload_view.dart index 15c983d..3896d3a 100644 --- a/lib/ui/views/upload_view.dart +++ b/lib/ui/views/upload_view.dart @@ -26,8 +26,7 @@ class UploadView extends StatelessWidget { } bool _isUploadButtonEnabled(UploadModel model) { - return model.pasteTextTouched || - (model.paths != null && model.paths!.length > 0); + return model.pasteTextTouched || (model.paths != null && model.paths!.length > 0); } Widget _render(UploadModel model, BuildContext context) { @@ -40,9 +39,7 @@ class UploadView extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.center, children: [ CircularProgressIndicator(), - (model.stateMessage != null && model.stateMessage!.isNotEmpty - ? Text(model.stateMessage!) - : Container()) + (model.stateMessage != null && model.stateMessage!.isNotEmpty ? Text(model.stateMessage!) : Container()) ])) : ListView(children: [ Padding( @@ -61,15 +58,12 @@ class UploadView extends StatelessWidget { color: buttonBackgroundColor, ), suffixIcon: IconButton( - onPressed: () => - model.pasteTextController.clear(), + onPressed: () => model.pasteTextController.clear(), icon: Icon(Icons.clear), ), hintText: translate('upload.text_to_be_pasted'), - contentPadding: - EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(32.0)), + contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0), + border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0)), ), controller: model.pasteTextController)), Padding( @@ -85,24 +79,20 @@ class UploadView extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.end, children: [ ElevatedButton.icon( - icon: Icon(Icons.file_copy_sharp, - color: blueColor), + icon: Icon(Icons.file_copy_sharp, color: blueColor), onPressed: () => model.openFileExplorer(), label: Text( translate('upload.open_file_explorer'), - style: - TextStyle(color: buttonForegroundColor), + style: TextStyle(color: buttonForegroundColor), )), ElevatedButton.icon( icon: Icon(Icons.cancel, color: orangeColor), - onPressed: model.paths != null && - model.paths!.length > 0 + onPressed: model.paths != null && model.paths!.length > 0 ? () => model.clearCachedFiles() : null, label: Text( translate('upload.clear_temporary_files'), - style: - TextStyle(color: buttonForegroundColor), + style: TextStyle(color: buttonForegroundColor), )), ], )), @@ -128,48 +118,35 @@ class UploadView extends StatelessWidget { onPressed: !_isUploadButtonEnabled(model) ? null : () async { - Map? items = - await model.upload(); - String? clipboardContent = model - .generatePasteLinks(items, url); + Map? items = await model.upload(); + String? clipboardContent = model.generatePasteLinks(items, url); - if (clipboardContent != null && - clipboardContent.isNotEmpty) { - FlutterClipboard.copy( - clipboardContent) - .then((value) { + if (clipboardContent != null && clipboardContent.isNotEmpty) { + FlutterClipboard.copy(clipboardContent).then((value) { final snackBar = SnackBar( action: SnackBarAction( - label: translate( - 'upload.dismiss'), + label: translate('upload.dismiss'), textColor: blueColor, onPressed: () { - ScaffoldMessenger.of( - context) - .hideCurrentSnackBar(); + ScaffoldMessenger.of(context).hideCurrentSnackBar(); }, ), - content: Text(translate( - 'upload.uploaded')), + content: Text(translate('upload.uploaded')), duration: Duration(seconds: 10), ); - ScaffoldMessenger.of(context) - .showSnackBar(snackBar); + ScaffoldMessenger.of(context).showSnackBar(snackBar); }); } }, - icon: Icon(Icons.upload_rounded, - color: greenColor), + icon: Icon(Icons.upload_rounded, color: greenColor), label: Text( translate('upload.upload'), - style: - TextStyle(color: buttonForegroundColor), + style: TextStyle(color: buttonForegroundColor), )), ])), model.errorMessage != null && model.errorMessage!.isNotEmpty ? (Padding( - padding: - const EdgeInsets.only(top: 10.0, bottom: 10.0), + padding: const EdgeInsets.only(top: 10.0, bottom: 10.0), child: CenteredErrorRow(model.errorMessage))) : Container(), Builder( @@ -181,28 +158,16 @@ class UploadView extends StatelessWidget { : model.paths != null ? Container( padding: const EdgeInsets.only(bottom: 30.0), - height: - MediaQuery.of(context).size.height * 0.50, + height: MediaQuery.of(context).size.height * 0.50, child: ListView.separated( - itemCount: model.paths != null && - model.paths!.isNotEmpty - ? model.paths!.length - : 1, - itemBuilder: - (BuildContext context, int index) { - final bool isMultiPath = - model.paths != null && - model.paths!.isNotEmpty; + itemCount: model.paths != null && model.paths!.isNotEmpty ? model.paths!.length : 1, + itemBuilder: (BuildContext context, int index) { + final bool isMultiPath = model.paths != null && model.paths!.isNotEmpty; final String name = (isMultiPath - ? model.paths! - .map((e) => e.name) - .toList()[index] + ? model.paths!.map((e) => e.name).toList()[index] : model.fileName ?? '...'); final path = model.paths!.length > 0 - ? model.paths! - .map((e) => e.path) - .toList()[index] - .toString() + ? model.paths!.map((e) => e.path).toList()[index].toString() : ''; return Card( @@ -213,9 +178,7 @@ class UploadView extends StatelessWidget { subtitle: Text(path), )); }, - separatorBuilder: - (BuildContext context, int index) => - const Divider(), + separatorBuilder: (BuildContext context, int index) => const Divider(), ), ) : Container(), diff --git a/lib/ui/widgets/swipe_navigation.dart b/lib/ui/widgets/swipe_navigation.dart index c2dc4cc..12dfb37 100644 --- a/lib/ui/widgets/swipe_navigation.dart +++ b/lib/ui/widgets/swipe_navigation.dart @@ -32,7 +32,6 @@ class _SwipeNavigationState extends State { @override Widget build(BuildContext context) { - return SimpleGestureDetector( - onHorizontalSwipe: _onHorizontalSwipe, child: widget.child!); + return SimpleGestureDetector(onHorizontalSwipe: _onHorizontalSwipe, child: widget.child!); } }