Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
# Include option is buggy:
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
analyzer:
errors:
unintended_html_in_doc_comment: ignore
# In case the include issue gets fixed, lines below INCLUDE_FIX
# can be removed

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
only_throw_errors: true
empty_constructor_bodies: true
no_duplicate_case_values: true
null_closures: true
prefer_conditional_assignment: true
constant_identifier_names: true
avoid_returning_null_for_void: true
annotate_overrides: true
avoid_empty_else: true
avoid_function_literals_in_foreach_calls: true
avoid_renaming_method_parameters: true
avoid_single_cascade_in_expression_statements: true
await_only_futures: true
exhaustive_cases: true
prefer_if_null_operators: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
14 changes: 14 additions & 0 deletions lib/get_common/obx_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ObxError implements Exception {
const ObxError();
@override
String toString() {
return """
[Get] the improper use of a GetX has been detected.
You should only use GetX or Obx for the specific widget that will be updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
""";
}
}
102 changes: 48 additions & 54 deletions lib/get_connect/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ abstract class GetConnectInterface with GetLifeCycleMixin {
Map<String, String>? headers,
});

GetSocket socket(
String url, {
Duration ping = const Duration(seconds: 5),
});
GetSocket socket(String url, {Duration ping = const Duration(seconds: 5)});
}

class GetConnect extends GetConnectInterface {
Expand Down Expand Up @@ -123,17 +120,18 @@ class GetConnect extends GetConnectInterface {

@override
GetHttpClient get httpClient => _httpClient ??= GetHttpClient(
userAgent: userAgent,
sendUserAgent: sendUserAgent,
timeout: timeout,
followRedirects: followRedirects,
maxRedirects: maxRedirects,
maxAuthRetries: maxAuthRetries,
allowAutoSignedCert: allowAutoSignedCert,
baseUrl: baseUrl,
trustedCertificates: trustedCertificates,
withCredentials: withCredentials,
findProxy: findProxy);
userAgent: userAgent,
sendUserAgent: sendUserAgent,
timeout: timeout,
followRedirects: followRedirects,
maxRedirects: maxRedirects,
maxAuthRetries: maxAuthRetries,
allowAutoSignedCert: allowAutoSignedCert,
baseUrl: baseUrl,
trustedCertificates: trustedCertificates,
withCredentials: withCredentials,
findProxy: findProxy,
);

@override
Future<Response<T>> get<T>(
Expand Down Expand Up @@ -262,10 +260,7 @@ class GetConnect extends GetConnectInterface {
}

@override
GetSocket socket(
String url, {
Duration ping = const Duration(seconds: 5),
}) {
GetSocket socket(String url, {Duration ping = const Duration(seconds: 5)}) {
_checkIfDisposed(isHttp: false);

final newSocket = GetSocket(_concatUrl(url)!, ping: ping);
Expand Down Expand Up @@ -305,33 +300,33 @@ class GetConnect extends GetConnectInterface {
Map<String, String>? headers,
}) async {
try {
final res = await post(
url,
{'query': query, 'variables': variables},
headers: headers,
);
final res = await post(url, {
'query': query,
'variables': variables,
}, headers: headers);

final listError = res.body['errors'];
if ((listError is List) && listError.isNotEmpty) {
return GraphQLResponse<T>(
graphQLErrors: listError
.map((e) => GraphQLError(
code: (e['extensions'] != null
graphQLErrors: listError
.map(
(e) => GraphQLError(
code:
(e['extensions'] != null
? e['extensions']['code'] ?? ''
: '')
.toString(),
message: (e['message'] ?? '').toString(),
))
.toList());
message: (e['message'] ?? '').toString(),
),
)
.toList(),
);
}
return GraphQLResponse<T>.fromResponse(res);
} on Exception catch (err) {
return GraphQLResponse<T>(graphQLErrors: [
GraphQLError(
code: null,
message: err.toString(),
)
]);
return GraphQLResponse<T>(
graphQLErrors: [GraphQLError(code: null, message: err.toString())],
);
}
}

Expand All @@ -343,30 +338,29 @@ class GetConnect extends GetConnectInterface {
Map<String, String>? headers,
}) async {
try {
final res = await post(
url,
{'query': mutation, 'variables': variables},
headers: headers,
);
final res = await post(url, {
'query': mutation,
'variables': variables,
}, headers: headers);

final listError = res.body['errors'];
if ((listError is List) && listError.isNotEmpty) {
return GraphQLResponse<T>(
graphQLErrors: listError
.map((e) => GraphQLError(
code: e['extensions']['code']?.toString(),
message: e['message']?.toString(),
))
.toList());
graphQLErrors: listError
.map(
(e) => GraphQLError(
code: e['extensions']['code']?.toString(),
message: e['message']?.toString(),
),
)
.toList(),
);
}
return GraphQLResponse<T>.fromResponse(res);
} on Exception catch (err) {
return GraphQLResponse<T>(graphQLErrors: [
GraphQLError(
code: null,
message: err.toString(),
)
]);
return GraphQLResponse<T>(
graphQLErrors: [GraphQLError(code: null, message: err.toString())],
);
}
}

Expand All @@ -376,7 +370,7 @@ class GetConnect extends GetConnectInterface {

void _checkIfDisposed({bool isHttp = true}) {
if (_isDisposed) {
throw 'Can not emit events to disposed clients';
throw Exception('Can not emit events to disposed clients');
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/get_connect/http/src/http/io/file_decoder_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ List<int> fileToBytes(dynamic data) {
if (File(data).existsSync()) {
return File(data).readAsBytesSync();
} else {
throw 'File $data not exists';
throw Exception('File $data not exists');
}
} else if (data is List<int>) {
return data;
} else {
throw const FormatException(
'File is not "File" or "String" or "List<int>"');
'File is not "File" or "String" or "List<int>"',
);
}
}

Expand Down
22 changes: 11 additions & 11 deletions lib/get_connect/sockets/src/sockets_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,46 @@ class BaseWebSocket {
this.ping = const Duration(seconds: 5),
this.allowSelfSigned = true,
}) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

Future connect() async {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void onOpen(OpenSocket fn) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void onClose(CloseSocket fn) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void onError(CloseSocket fn) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void onMessage(MessageSocket fn) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void on(String event, MessageSocket message) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void close([int? status, String? reason]) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void send(dynamic data) async {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void dispose() {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}

void emit(String event, dynamic data) {
throw 'To use sockets you need dart:io or dart:html';
throw Exception('To use sockets you need dart:io or dart:html');
}
}
41 changes: 20 additions & 21 deletions lib/get_instance/src/extension_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ extension Inst on GetInterface {
// );
// }

S put<S>(
S dependency, {
String? tag,
bool permanent = false,
}) {
S put<S>(S dependency, {String? tag, bool permanent = false}) {
_insert(
isSingleton: true,
name: tag,
permanent: permanent,
builder: (() => dependency));
isSingleton: true,
name: tag,
permanent: permanent,
builder: (() => dependency),
);
return find<S>(tag: tag);
}

Expand Down Expand Up @@ -201,8 +198,9 @@ extension Inst on GetInterface {

if (isSingleton) {
if (Get.smartManagement != SmartManagement.onlyBuilder) {
RouterReportManager.instance
.reportDependencyLinkedToRoute(_getKey(S, name));
RouterReportManager.instance.reportDependencyLinkedToRoute(
_getKey(S, name),
);
}
}
}
Expand Down Expand Up @@ -281,9 +279,9 @@ extension Inst on GetInterface {
final dep = _singl[key];
if (dep == null) {
if (tag == null) {
throw 'Class "$S" is not registered';
throw Exception('Class "$S" is not registered');
} else {
throw 'Class "$S" with tag "$tag" is not registered';
throw Exception('Class "$S" with tag "$tag" is not registered');
}
}

Expand All @@ -294,7 +292,9 @@ extension Inst on GetInterface {
return i ?? dep.getDependency() as S;
} else {
// ignore: lines_longer_than_80_chars
throw '"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"';
throw Exception(
'"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"',
);
}
}

Expand Down Expand Up @@ -324,8 +324,11 @@ extension Inst on GetInterface {
///
/// Note: if fenix is not provided it will be set to true if
/// the parent instance was permanent
void lazyReplace<P>(InstanceBuilderCallback<P> builder,
{String? tag, bool? fenix}) {
void lazyReplace<P>(
InstanceBuilderCallback<P> builder, {
String? tag,
bool? fenix,
}) {
final info = getInstanceInfo<P>(tag: tag);
final permanent = (info.isPermanent ?? false);
delete<P>(tag: tag, force: permanent);
Expand Down Expand Up @@ -436,11 +439,7 @@ extension Inst on GetInterface {
});
}

void reload<S>({
String? tag,
String? key,
bool force = false,
}) {
void reload<S>({String? tag, String? key, bool force = false}) {
final newKey = key ?? _getKey(S, tag);

final builder = _getDependency<S>(tag: tag, key: newKey);
Expand Down
Loading