-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
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>); |
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.
Can be moved to the package and only transfer TV object
TizenHelperMethods.selectedTv!.socketStream()?.listen((event) { | ||
print(event); | ||
TizenHelperMethods.log("Received a message: $event"); |
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 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"); |
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.
Same
Map json = jsonDecode(event); | ||
String? token = json["data"]["token"]; | ||
if (token != null) { | ||
TizenHelperMethods.log("Received a new token: $token"); |
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.
Decoding of the token should be part of the package.
TizenHelperMethods.selectedTv = | ||
tvs.firstWhere((element) => element.name == tv); |
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.
setState preferably should not contain calculations.
onPressed: () { | ||
_pressKey(KeyCodes.KEY_POWER); | ||
] | ||
: [], |
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.
maybe null is representing it better?, it should be the same as the default value.
: [], | ||
), | ||
body: connectedToTV | ||
? buildConnectedTVUI |
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.
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" |
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.
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; |
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 will destroy bad certificates for all the apps that will use our package.
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.
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
}
(X509Certificate cert, String host, int port) => | ||
TizenHelperMethods.selectedTv?.device.ip != null && | ||
host == TizenHelperMethods.selectedTv?.device.ip; | ||
(X509Certificate cert, String host, int port) => true; |
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.
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
}
No description provided.