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

Example refactored #8

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

Example refactored #8

wants to merge 2 commits into from

Conversation

shaharhn
Copy link
Collaborator

@shaharhn shaharhn commented May 1, 2024

No description provided.

@shaharhn shaharhn requested a review from guyluz11 May 1, 2024 23:00
Comment on lines +79 to +86
try {
Socket socket = await socketTask;
String ip = socket.address.address;
socket.destroy();
TizenHelperMethods.log('Checking TV at $ip');
Response response = await Dio().get("http://$ip:8001/api/v2/");
TizenHelperMethods.log('Found TV at $ip');
TV tv = TV.fromJson(response.data as Map<String, dynamic>);
Copy link
Member

Choose a reason for hiding this comment

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

Can be moved to the package and only transfer TV object

TizenHelperMethods.selectedTv!.socketStream()?.listen((event) {
print(event);
TizenHelperMethods.log("Received a message: $event");
Copy link
Member

Choose a reason for hiding this comment

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

The package should log itself, app should log itself separately.

Map json = jsonDecode(event);
String? token = json["data"]["token"];
if (token != null) {
TizenHelperMethods.log("Received a new token: $token");
Copy link
Member

Choose a reason for hiding this comment

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

Same

Comment on lines +106 to +109
Map json = jsonDecode(event);
String? token = json["data"]["token"];
if (token != null) {
TizenHelperMethods.log("Received a new token: $token");
Copy link
Member

Choose a reason for hiding this comment

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

Decoding of the token should be part of the package.

Comment on lines +136 to +137
TizenHelperMethods.selectedTv =
tvs.firstWhere((element) => element.name == tv);
Copy link
Member

Choose a reason for hiding this comment

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

setState preferably should not contain calculations.

onPressed: () {
_pressKey(KeyCodes.KEY_POWER);
]
: [],
Copy link
Member

Choose a reason for hiding this comment

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

maybe null is representing it better?, it should be the same as the default value.

: [],
),
body: connectedToTV
? buildConnectedTVUI
Copy link
Member

Choose a reason for hiding this comment

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

We should use Tv and Ui just to make our naming consistent

children: [
if (tvs.isNotEmpty)
Text(_connectedTv != TizenHelperMethods.selectedTv
? "Waiting for TV to connect"
Copy link
Member

Choose a reason for hiding this comment

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

Some text us using " and some using ', consistency is key.
We need to define it in the lint.

' should be the standard as " is more common in other things like JSON (for translations), so searching text would be easier.

(X509Certificate cert, String host, int port) =>
TizenHelperMethods.selectedTv?.device.ip != null &&
host == TizenHelperMethods.selectedTv?.device.ip;
(X509Certificate cert, String host, int port) => true;
Copy link
Member

Choose a reason for hiding this comment

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

This will destroy bad certificates for all the apps that will use our package.

Copy link
Member

Choose a reason for hiding this comment

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

Please try to replace this with runZoned in the required area :)

import 'dart:io';

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
  }
}

void main() {
  HttpOverrides.runZoned(
    () {
      // Your HTTP requests here will use the overridden behavior
      var client = HttpClient();
      // Use your client for specific requests
    },
    createHttpClient: (SecurityContext? context) => MyHttpOverrides().createHttpClient(context),
  );

  // Other HTTP requests outside this zone are unaffected
}

@guyluz11 guyluz11 linked an issue May 1, 2024 that may be closed by this pull request
(X509Certificate cert, String host, int port) =>
TizenHelperMethods.selectedTv?.device.ip != null &&
host == TizenHelperMethods.selectedTv?.device.ip;
(X509Certificate cert, String host, int port) => true;
Copy link
Member

Choose a reason for hiding this comment

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

Please try to replace this with runZoned in the required area :)

import 'dart:io';

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
  }
}

void main() {
  HttpOverrides.runZoned(
    () {
      // Your HTTP requests here will use the overridden behavior
      var client = HttpClient();
      // Use your client for specific requests
    },
    createHttpClient: (SecurityContext? context) => MyHttpOverrides().createHttpClient(context),
  );

  // Other HTTP requests outside this zone are unaffected
}

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.

TizenHelperMethods scanForDevices need work
2 participants