Skip to content

Commit

Permalink
- Code formatting
Browse files Browse the repository at this point in the history
- Updated version for prerelease

Signed-off-by: Ayon Das <[email protected]>
  • Loading branch information
AyonAB committed Nov 6, 2022
1 parent 0c04571 commit 9e6828f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 34 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@

## 0.2.0-dev.4

* App bundle build issue fix.
* App bundle build issue fix.

## 0.2.0-dev.5

* Removed unnecessary platform exceptions.
* Updated dependencies.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.asdevs.signalr_flutter

import android.os.Handler
import android.os.Looper
import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import microsoft.aspnet.signalr.client.ConnectionState
Expand All @@ -23,12 +22,12 @@ class SignalrFlutterPlugin : FlutterPlugin, SignalrApi.SignalRHostApi {
private lateinit var signalrApi: SignalrApi.SignalRPlatformApi

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
SignalrApi.SignalRHostApi.setup(flutterPluginBinding.binaryMessenger, this);
SignalrApi.SignalRHostApi.setup(flutterPluginBinding.binaryMessenger, this)
signalrApi = SignalrApi.SignalRPlatformApi(flutterPluginBinding.binaryMessenger)
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
SignalrApi.SignalRHostApi.setup(binding.binaryMessenger, null);
SignalrApi.SignalRHostApi.setup(binding.binaryMessenger, null)
}

override fun connect(
Expand Down
8 changes: 5 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class _MyAppState extends State<MyApp> {
style: Theme.of(context).textTheme.headline6),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: ElevatedButton(onPressed: _buttonTapped, child: const Text("Invoke Method")),
child: ElevatedButton(
onPressed: _buttonTapped,
child: const Text("Invoke Method")),
)
],
),
Expand Down Expand Up @@ -88,8 +90,8 @@ class _MyAppState extends State<MyApp> {

void _buttonTapped() async {
try {
final result =
await signalR.invokeMethod("<Your Method Name>", arguments: ["<Your Method Arguments>"]);
final result = await signalR.invokeMethod("<Your Method Name>",
arguments: ["<Your Method Arguments>"]);
print(result);
} catch (e) {
print(e);
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.0-dev.4"
version: "0.2.0-dev.5"
sky_engine:
dependency: transitive
description: flutter
Expand Down
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data!.startsWith('Running on:'),
(Widget widget) =>
widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
56 changes: 36 additions & 20 deletions lib/signalr_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ class ConnectionOptions {
hubName: pigeonMap['hubName'] as String?,
queryString: pigeonMap['queryString'] as String?,
hubMethods: (pigeonMap['hubMethods'] as List<Object?>?)?.cast<String?>(),
headers: (pigeonMap['headers'] as Map<Object?, Object?>?)?.cast<String?, String?>(),
transport:
pigeonMap['transport'] != null ? Transport.values[pigeonMap['transport']! as int] : null,
headers: (pigeonMap['headers'] as Map<Object?, Object?>?)
?.cast<String?, String?>(),
transport: pigeonMap['transport'] != null
? Transport.values[pigeonMap['transport']! as int]
: null,
);
}
}
Expand Down Expand Up @@ -89,8 +91,9 @@ class StatusChangeResult {
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
return StatusChangeResult(
connectionId: pigeonMap['connectionId'] as String?,
status:
pigeonMap['status'] != null ? ConnectionStatus.values[pigeonMap['status']! as int] : null,
status: pigeonMap['status'] != null
? ConnectionStatus.values[pigeonMap['status']! as int]
: null,
errorMessage: pigeonMap['errorMessage'] as String?,
);
}
Expand Down Expand Up @@ -124,7 +127,8 @@ class SignalRHostApi {
/// Constructor for [SignalRHostApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform.
SignalRHostApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger;
SignalRHostApi({BinaryMessenger? binaryMessenger})
: _binaryMessenger = binaryMessenger;
final BinaryMessenger? _binaryMessenger;

static const MessageCodec<Object?> codec = _SignalRHostApiCodec();
Expand All @@ -133,15 +137,16 @@ class SignalRHostApi {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.SignalRHostApi.connect', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(<Object?>[arg_connectionOptions]) as Map<Object?, Object?>?;
final Map<Object?, Object?>? replyMap = await channel
.send(<Object?>[arg_connectionOptions]) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
Expand All @@ -161,14 +166,16 @@ class SignalRHostApi {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.SignalRHostApi.reconnect', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap = await channel.send(null) as Map<Object?, Object?>?;
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
Expand All @@ -188,14 +195,16 @@ class SignalRHostApi {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.SignalRHostApi.stop', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap = await channel.send(null) as Map<Object?, Object?>?;
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
Expand All @@ -210,14 +219,16 @@ class SignalRHostApi {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.SignalRHostApi.isConnected', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap = await channel.send(null) as Map<Object?, Object?>?;
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
Expand All @@ -233,19 +244,22 @@ class SignalRHostApi {
}
}

Future<String> invokeMethod(String arg_methodName, List<String?> arg_arguments) async {
Future<String> invokeMethod(
String arg_methodName, List<String?> arg_arguments) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.SignalRHostApi.invokeMethod', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(<Object?>[arg_methodName, arg_arguments]) as Map<Object?, Object?>?;
await channel.send(<Object?>[arg_methodName, arg_arguments])
as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
Expand Down Expand Up @@ -291,7 +305,8 @@ abstract class SignalRPlatformApi {

Future<void> onStatusChange(StatusChangeResult statusChangeResult);
Future<void> onNewMessage(String hubName, String message);
static void setup(SignalRPlatformApi? api, {BinaryMessenger? binaryMessenger}) {
static void setup(SignalRPlatformApi? api,
{BinaryMessenger? binaryMessenger}) {
{
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.SignalRPlatformApi.onStatusChange', codec,
Expand All @@ -303,7 +318,8 @@ abstract class SignalRPlatformApi {
assert(message != null,
'Argument for dev.flutter.pigeon.SignalRPlatformApi.onStatusChange was null.');
final List<Object?> args = (message as List<Object?>?)!;
final StatusChangeResult? arg_statusChangeResult = (args[0] as StatusChangeResult?);
final StatusChangeResult? arg_statusChangeResult =
(args[0] as StatusChangeResult?);
assert(arg_statusChangeResult != null,
'Argument for dev.flutter.pigeon.SignalRPlatformApi.onStatusChange was null, expected non-null StatusChangeResult.');
await api.onStatusChange(arg_statusChangeResult!);
Expand Down
6 changes: 4 additions & 2 deletions lib/signalr_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ class SignalR extends SignalrPlatformInterface implements SignalRPlatformApi {

/// Invoke any server method with optional [arguments].
@override
Future<String> invokeMethod(String methodName, {List<String>? arguments}) async {
Future<String> invokeMethod(String methodName,
{List<String>? arguments}) async {
try {
return await _signalrApi.invokeMethod(methodName, arguments ?? List.empty());
return await _signalrApi.invokeMethod(
methodName, arguments ?? List.empty());
} catch (e) {
return Future.error(e);
}
Expand Down
3 changes: 2 additions & 1 deletion pigeons/signalr_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void configurePigeon(PigeonOptions opts) {
dartOut: '../lib/signalr_api.dart',
objcHeaderOut: 'ios/Classes/signalr_api.h',
objcSourceOut: 'ios/Classes/signalr_api.m',
javaOut: 'android/src/main/java/dev/asdevs/signalr_flutter/Signalr_Api.java',
javaOut:
'android/src/main/java/dev/asdevs/signalr_flutter/Signalr_Api.java',
);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: signalr_flutter
description: A flutter plugin for .net SignalR client. This client is for ASP.Net SignalR, not for .Net Core SignalR.
version: 0.2.0-dev.4
version: 0.2.0-dev.5
homepage: https://pub.dev/packages/signalr_flutter

environment:
Expand Down

0 comments on commit 9e6828f

Please sign in to comment.