Apply Flutter best practices [Non-Breaking] (#2)

* Add flutter_lints package

* Use key in widget constructors

lint: use_key_in_widget_constructors

* Unnecessary new keyword

lint: unnecessary_new

* Prefer const with constant constructors

* Exclude protobuf files from analyzer

* Private field could be final

* Annotate overridden members

* Use initializing formals when possible

* Don't access members with `this` unless avoiding shadowing

* Prefer is! operator

* Use isEmpty instead of length

* Use collection literals when possible

* Revert comment changes

* Cleaner null testing

* Misc fixes

* Avoid using `forEach` with a function literal

* Prefer `final` over `var` where applicable

* Enforce stricter type-checking

* Ignore VS Code files

* Flutter format

* Prefer using lowerCamelCase for constant names

* flutter format -l 100

* Disable `avoid_print` for examples

* Slight improvements to example

Should solve lint error: no_logic_in_create_state
This commit is contained in:
Hiroshi Horie
2021-08-31 16:35:07 +09:00
committed by GitHub
parent 4a75d78ef9
commit ab31ddabb9
41 changed files with 904 additions and 1228 deletions
+22 -14
View File
@@ -4,17 +4,16 @@ class RTCConfiguration {
String? iceTransportPolicy;
Map<String, dynamic> toMap() {
var iceServersMap = [];
iceServers?.forEach((element) {
final iceServersMap = <Map<String, dynamic>>[];
for (final element in (iceServers ?? <RTCIceServer>[])) {
iceServersMap.add(element.toMap());
});
return {
}
return <String, dynamic>{
// only supports unified plan
'sdpSemantics': 'unified-plan',
if (iceCandidatePoolSize != null)
"iceCandidatePoolSize": iceCandidatePoolSize,
"iceServers": iceServersMap,
if (iceTransportPolicy != null) "iceTransportPolicy": iceTransportPolicy,
if (iceCandidatePoolSize != null) 'iceCandidatePoolSize': iceCandidatePoolSize,
'iceServers': iceServersMap,
if (iceTransportPolicy != null) 'iceTransportPolicy': iceTransportPolicy,
};
}
}
@@ -27,13 +26,22 @@ class RTCIceServer {
RTCIceServer({required this.urls, this.username, this.credential});
Map<String, dynamic> toMap() {
return {
"urls": urls,
if (username != null) "username": username,
if (credential != null) "credential": credential,
return <String, dynamic>{
'urls': urls,
if (username != null) 'username': username,
if (credential != null) 'credential': credential,
};
}
}
const RTCIceTransportPolicyAll = 'all';
const RTCIceTransportPolicyRelay = 'relay';
enum RTCIceTransportPolicy {
all,
relay,
}
extension RTCIceTransportPolicyExt on RTCIceTransportPolicy {
String toStringValue() => {
RTCIceTransportPolicy.all: 'all',
RTCIceTransportPolicy.relay: 'relay',
}[this]!;
}