Skip to content

Commit ae61ca7

Browse files
committed
- BREAKING CHANGE: all Error methods and functions renamed to Exceptions.
- BREAKING CHANGE: Dart API >= 2.13.0 - feat: flutter_lints and analysis_options to get most better way style the code - fix: linter errors and code style improvements - fix: some Errors were replaced by Exceptions, some Exceptions became Errors to make more correct way of using Exceptions and Errors
1 parent b22d7d8 commit ae61ca7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1261
-963
lines changed

CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# 3.1.0
2+
3+
- BREAKING CHANGE: all `Error` methods and functions renamed to `Exception`.
4+
The reason of it is a nature between Exception and Error in dart.
5+
In short:
6+
`Exceptions` should be used when there is a problem that is expected.
7+
A common one is any type of I/O operation (like network traffic), where the socket closes early, and trying to write data to that socket fails.
8+
`Errors` occur when there is a problem that was not expected. Things like null pointers (you expected this variable to not be null), running our of memory, etc... When you try to use the API in a wrong way or stuffs like that.
9+
`For the most part` you, as an app developer, will always `use exceptions`.
10+
Errors tend to be reserved for unexpected and fatal problems.
11+
source:
12+
https://stackoverflow.com/questions/17315945/error-vs-exception-in-dart
13+
- BREAKING CHANGE: Dart API >= 2.13.0
14+
- feat: flutter_lints and analysis_options to get most better way style the code
15+
- fix: linter errors and code style improvements
16+
- fix: some Errors were replaced by Exceptions, some Exceptions became Errors to make more correct way of using Exceptions and Errors
17+
118
# 3.0.0
219

320
- BREAKING CHANAGE: rename Uhst to UHST

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ host
6060
_hostIdController.text = hostId;
6161
});
6262
})
63-
..onError(handler: ({required dynamic error}) {
64-
print('error received! $error');
65-
if (error is HostIdAlreadyInUse) {
63+
..onException(handler: ({required dynamic exception}) {
64+
print('exception received! $exception');
65+
if (exception is HostIdAlreadyInUse) {
6666
// this is expected if you refresh the page
6767
// connection is still alive on the relay
6868
// just need to wait
@@ -72,7 +72,7 @@ host
7272
});
7373
} else {
7474
setState(() {
75-
hostMessages.add(error.toString());
75+
hostMessages.add(exception.toString());
7676
});
7777
}
7878
})
@@ -125,14 +125,14 @@ client
125125
clientMessages.add('Client received: $message');
126126
});
127127
})
128-
..onError(handler: ({required dynamic error}) {
129-
if (error is InvalidHostId || error is InvalidClientOrHostId) {
128+
..onException(handler: ({required dynamic exception}) {
129+
if (exception is InvalidHostId || exception is InvalidClientOrHostId) {
130130
setState(() {
131131
clientMessages.add('Invalid hostId!');
132132
});
133133
} else {
134134
setState(() {
135-
clientMessages.add(error.toString());
135+
clientMessages.add(exception.toString());
136136
});
137137
}
138138
})

analysis_options.yaml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
analyzer:
12+
exclude:
13+
- example/
14+
linter:
15+
# The lint rules applied to this project can be customized in the
16+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
17+
# included above or to enable additional rules. A list of all available lints
18+
# and their documentation is published at
19+
# https://dart-lang.github.io/linter/lints/index.html.
20+
#
21+
# Instead of disabling a lint rule for the entire project in the
22+
# section below, it can also be suppressed for a single line of code
23+
# or a specific dart file by using the `// ignore: name_of_lint` and
24+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
25+
# producing the lint.
26+
rules:
27+
# Errors
28+
use_build_context_synchronously: true
29+
unnecessary_statements: true
30+
throw_in_finally: true
31+
test_types_in_equals: true
32+
no_adjacent_strings_in_list: true
33+
literal_only_boolean_expressions: true
34+
invariant_booleans: true
35+
diagnostic_describe_all_properties: true
36+
comment_references: false
37+
close_sinks: true
38+
cancel_subscriptions: true
39+
avoid_type_to_string: true
40+
avoid_slow_async_io: true
41+
avoid_returning_null_for_future: true
42+
avoid_dynamic_calls: true
43+
prefer_relative_imports: true
44+
# Style
45+
avoid_void_async: true
46+
avoid_setters_without_getters: true
47+
avoid_returning_this: true
48+
avoid_returning_null: true
49+
avoid_redundant_argument_values: true
50+
avoid_private_typedef_functions: true
51+
avoid_positional_boolean_parameters: true
52+
avoid_multiple_declarations_per_line: true
53+
avoid_js_rounded_ints: true
54+
avoid_implementing_value_types: true
55+
avoid_field_initializers_in_const_classes: true
56+
avoid_escaping_inner_quotes: true
57+
avoid_equals_and_hash_code_on_mutable_classes: true
58+
avoid_double_and_int_checks: true
59+
avoid_classes_with_only_static_members: true
60+
avoid_catching_errors: true
61+
avoid_catches_without_on_clauses: true
62+
avoid_bool_literals_in_conditional_expressions: true
63+
always_put_required_named_parameters_first: true
64+
always_declare_return_types: true
65+
avoid_unused_constructor_parameters: true
66+
avoid_types_on_closure_parameters: true
67+
cast_nullable_to_non_nullable: true
68+
cascade_invocations: true
69+
deprecated_consistency: true
70+
directives_ordering: true
71+
flutter_style_todos: true
72+
join_return_with_assignment: true
73+
leading_newlines_in_multiline_strings: true
74+
library_private_types_in_public_api: true
75+
lines_longer_than_80_chars: true
76+
missing_whitespace_between_adjacent_strings: true
77+
no_runtimeType_toString: true
78+
noop_primitive_operations: true
79+
null_check_on_nullable_type_parameter: true
80+
one_member_abstracts: true
81+
package_api_docs: true
82+
only_throw_errors: true
83+
parameter_assignments: true
84+
prefer_asserts_in_initializer_lists: true
85+
prefer_asserts_with_message: true
86+
prefer_constructors_over_static_methods: true
87+
prefer_single_quotes: true
88+
prefer_expression_function_bodies: true
89+
prefer_final_in_for_each: true
90+
prefer_final_locals: true
91+
prefer_final_parameters: true
92+
prefer_if_elements_to_conditional_expressions: true
93+
prefer_interpolation_to_compose_strings: true
94+
prefer_mixin: true
95+
prefer_null_aware_method_calls: true
96+
public_member_api_docs: true
97+
require_trailing_commas: true
98+
sort_child_properties_last: true
99+
sort_constructors_first: true
100+
sort_unnamed_constructors_first: true
101+
tighten_type_of_initializing_formals: true
102+
type_annotate_public_apis: true
103+
unawaited_futures: true
104+
unnecessary_await_in_return: true
105+
unnecessary_lambdas: true
106+
unnecessary_null_aware_assignments: true
107+
unnecessary_null_checks: true
108+
unnecessary_nullable_for_final_variable_declarations: true
109+
unnecessary_parenthesis: true
110+
unnecessary_raw_strings: true
111+
use_is_even_rather_than_modulo: true
112+
use_named_constants: true
113+
use_raw_strings: true
114+
use_setters_to_change_properties: true
115+
use_string_buffers: true
116+
use_test_throws_matchers: true
117+
use_to_and_as_if_applicable: true
118+
depend_on_referenced_packages: true
119+
# avoid_classes_with_only_static_members: false
120+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
121+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
122+
# Additional information about this file can be found at
123+
# https://dart.dev/guides/language/analysis-options

0 commit comments

Comments
 (0)