Skip to content
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

Implement null safety #163

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Implement null safety #163

wants to merge 11 commits into from

Conversation

ihancock
Copy link

First pass untested

@ihancock
Copy link
Author

@tiholic any chance of approving?

Copy link
Contributor

@tiholic tiholic left a 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;
Copy link
Contributor

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?

Copy link
Author

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);
// }
Copy link
Contributor

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.

Copy link
Author

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.

List<String> toPrint = ['trying to connect'];
SocketIOManager manager;
List<String?> toPrint = ['trying to connect'];
SocketIOManager? manager;
Copy link
Contributor

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

Copy link
Author

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>{};
Copy link
Contributor

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.

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

late instead of ?

Copy link
Author

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(
Copy link
Contributor

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 !

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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;
Copy link
Contributor

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

@tiholic
Copy link
Contributor

tiholic commented Mar 31, 2022

@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

@carman247
Copy link

Is this ever going to be completed? Seems to be some issues with the SocketManager's clearInstance method, I'm not sure if that's been fixed on other branches since.

@Pilaba
Copy link

Pilaba commented Sep 16, 2023

It's been a while without any input.
can we expected null safety anytime soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants