-
Notifications
You must be signed in to change notification settings - Fork 113
Implement null safety #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@tiholic any chance of approving? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ihancock, based on a quick review, here are a few comments. I think are all appropriate in nullsafety
context.
private final Registrar registrar; | ||
private final StreamsChannel streamsChannel; | ||
private FlutterPluginBinding flutterPluginBinding; | ||
private StreamsChannel streamsChannel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reason for streamsChannel
not being final
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new Android embedding 2.0 calls the default constructor initially (very annoying) so we can not initializer the stream channel. The onAttachedToEngine calls our private constructor which initializes StreamChannel. If the default constructor did not get called or we set a dummy value for it ion this constructor then that would work but is not very elegant.
// final AdharaSocketIoPlugin plugin = new AdharaSocketIoPlugin(registrar, streamsChannel); | ||
// final MethodChannel channel = new MethodChannel(registrar.messenger(), PlatformConstants.MethodChannelNames.managerMethodChannel); | ||
// channel.setMethodCallHandler(plugin); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to avoid unwanted commented code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not agree more. I will remove.
example/lib/main.dart
Outdated
List<String> toPrint = ['trying to connect']; | ||
SocketIOManager manager; | ||
List<String?> toPrint = ['trying to connect']; | ||
SocketIOManager? manager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be late SocketIOManager manager
, thus avoiding the need to add manager!
everywhere else in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes agreed
lib/manager.dart
Outdated
@@ -33,7 +33,7 @@ class SocketIOManager { | |||
MethodChannelNames.streamsChannel, | |||
); | |||
|
|||
final _sockets = <int, SocketIO>{}; | |||
final _sockets = <int?, SocketIO>{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the key is supposed to be strict int
. Any other possibilities are to be filtered out in usages below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that: -
final index = await _channel.invokeMethod(
PlatformMethod.newInstance,
{
'options': options.asMap(),
'clear': _clearExisting,
},
);
Returns a Future<int?> as per the MethodChannel contract so we would need to provide a default with ??.
completer.complete(arguments); | ||
} | ||
}); | ||
} | ||
|
||
Completer _connectSyncCompleter; | ||
Completer? _connectSyncCompleter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
late
instead of ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You set it to null in: -
void cleanup() {
onConnectSubscription.cancel();
onConnectErrorSubscription.cancel();
_connectSyncCompleter = null;
}
So it has to have the ?
lib/socket.dart
Outdated
@@ -120,7 +128,7 @@ class SocketIO { | |||
} | |||
|
|||
/// checks whether connection is alive | |||
Future<bool> isConnected() => _channel.invokeMethod( | |||
Future<bool?> isConnected() => _channel.invokeMethod( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can implement a method that ensures returning of null-safe values like the one i created here would avoid usage of unwanted ?
and !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will throw an exception, it does mean we have to await though.
pubspec.yaml
Outdated
flutter: ">=1.22.6" | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
pedantic: ^1.9.2 | ||
|
||
dev_dependencies: | ||
adhara_socket_io_example: | ||
path: example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the need for example as a dev dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot there reason why, but I have removed it now.
@@ -11,7 +11,7 @@ import 'streams_channel.dart'; | |||
/// A socket instance internally used by the [SocketIOManager] | |||
class SocketIO { | |||
/// Socket -or- Connection identifier | |||
final int id; | |||
final int? id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id
should not be nullable
@ihancock I see the support for minSDK version is changed from 16 to 21. What is the reason for increasing the min value? And if it is justifyable, we can also remove unwanted android versions from workflow files |
Is this ever going to be completed? Seems to be some issues with the |
It's been a while without any input. |
First pass untested