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
+13 -21
View File
@@ -13,15 +13,12 @@ class LocalVideoTrack extends VideoTrack {
: super(name, mediaTrack, stream);
/// Creates a LocalVideoTrack from camera input.
static Future<LocalVideoTrack> createCameraTrack(
[LocalVideoTrackOptions? options]) async {
if (options == null) {
options = LocalVideoTrackOptions(params: VideoPresets.qhd);
}
static Future<LocalVideoTrack> createCameraTrack([LocalVideoTrackOptions? options]) async {
options ??= LocalVideoTrackOptions(params: VideoPresets.qhd);
try {
var stream = await _createCameraStream(options);
return LocalVideoTrack("camera", stream.getVideoTracks().first, stream);
final stream = await _createCameraStream(options);
return LocalVideoTrack('camera', stream.getVideoTracks().first, stream);
} catch (e) {
return Future.error(e);
}
@@ -34,13 +31,11 @@ class LocalVideoTrack extends VideoTrack {
return Future.error(TrackCreateError('could not restart track'));
}
if (options == null) {
options = LocalVideoTrackOptions(params: VideoPresets.qhd);
}
options ??= LocalVideoTrackOptions(params: VideoPresets.qhd);
try {
var stream = await _createCameraStream(options);
var track = stream.getVideoTracks().first;
final stream = await _createCameraStream(options);
final track = stream.getVideoTracks().first;
mediaStream = stream;
await mediaTrack.stop();
mediaTrack = track;
@@ -50,19 +45,16 @@ class LocalVideoTrack extends VideoTrack {
}
}
static Future<MediaStream> _createCameraStream(
LocalVideoTrackOptions? options) async {
if (options == null) {
options = LocalVideoTrackOptions(params: VideoPresets.qhd);
}
static Future<MediaStream> _createCameraStream(LocalVideoTrackOptions? options) async {
options ??= LocalVideoTrackOptions(params: VideoPresets.qhd);
try {
var stream = await navigator.mediaDevices.getUserMedia({
"audio": false,
"video": options.mediaConstraints,
final stream = await navigator.mediaDevices.getUserMedia(<String, dynamic>{
'audio': false,
'video': options.mediaConstraints,
});
if (stream.getVideoTracks().length == 0) {
if (stream.getVideoTracks().isEmpty) {
return Future.error(TrackCreateError());
}