Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 32bb3f8

Browse files
committed
made httpheaders not null
1 parent c702665 commit 32bb3f8

File tree

11 files changed

+71
-39
lines changed

11 files changed

+71
-39
lines changed

packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/Messages.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,22 @@ public void setFormatHint(@Nullable String setterArg) {
419419
this.formatHint = setterArg;
420420
}
421421

422-
private @Nullable Map<String, String> httpHeaders;
422+
private @NonNull Map<String, String> httpHeaders;
423423

424-
public @Nullable Map<String, String> getHttpHeaders() {
424+
public @NonNull Map<String, String> getHttpHeaders() {
425425
return httpHeaders;
426426
}
427427

428-
public void setHttpHeaders(@Nullable Map<String, String> setterArg) {
428+
public void setHttpHeaders(@NonNull Map<String, String> setterArg) {
429+
if (setterArg == null) {
430+
throw new IllegalStateException("Nonnull field \"httpHeaders\" is null.");
431+
}
429432
this.httpHeaders = setterArg;
430433
}
431434

435+
/** Constructor is private to enforce null safety; use Builder. */
436+
private CreateMessage() {}
437+
432438
public static class Builder {
433439
private @Nullable String asset;
434440

@@ -460,7 +466,7 @@ public static class Builder {
460466

461467
private @Nullable Map<String, String> httpHeaders;
462468

463-
public @NonNull Builder setHttpHeaders(@Nullable Map<String, String> setterArg) {
469+
public @NonNull Builder setHttpHeaders(@NonNull Map<String, String> setterArg) {
464470
this.httpHeaders = setterArg;
465471
return this;
466472
}

packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.content.Context;
1111
import android.net.Uri;
1212
import android.view.Surface;
13+
import androidx.annotation.NonNull;
1314
import com.google.android.exoplayer2.C;
1415
import com.google.android.exoplayer2.ExoPlaybackException;
1516
import com.google.android.exoplayer2.Format;
@@ -64,7 +65,7 @@ final class VideoPlayer {
6465
TextureRegistry.SurfaceTextureEntry textureEntry,
6566
String dataSource,
6667
String formatHint,
67-
Map<String, String> httpHeaders,
68+
@NonNull Map<String, String> httpHeaders,
6869
VideoPlayerOptions options) {
6970
this.eventChannel = eventChannel;
7071
this.textureEntry = textureEntry;

packages/video_player/video_player_android/lib/src/android_video_player.dart

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,35 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
3333

3434
@override
3535
Future<int?> create(DataSource dataSource) async {
36-
final CreateMessage message = CreateMessage();
37-
36+
String? asset;
37+
String? packageName;
38+
String? uri;
39+
String? formatHint;
40+
Map<String, String> httpHeaders = <String, String>{};
3841
switch (dataSource.sourceType) {
3942
case DataSourceType.asset:
40-
message.asset = dataSource.asset;
41-
message.packageName = dataSource.package;
43+
asset = dataSource.asset;
44+
packageName = dataSource.package;
4245
break;
4346
case DataSourceType.network:
44-
message.uri = dataSource.uri;
45-
message.formatHint = _videoFormatStringMap[dataSource.formatHint];
46-
message.httpHeaders = dataSource.httpHeaders;
47+
uri = dataSource.uri;
48+
formatHint = _videoFormatStringMap[dataSource.formatHint];
49+
httpHeaders = dataSource.httpHeaders;
4750
break;
4851
case DataSourceType.file:
49-
message.uri = dataSource.uri;
52+
uri = dataSource.uri;
5053
break;
5154
case DataSourceType.contentUri:
52-
message.uri = dataSource.uri;
55+
uri = dataSource.uri;
5356
break;
5457
}
58+
final CreateMessage message = CreateMessage(
59+
asset: asset,
60+
packageName: packageName,
61+
uri: uri,
62+
httpHeaders: httpHeaders,
63+
formatHint: formatHint,
64+
);
5565

5666
final TextureMessage response = await _api.create(message);
5767
return response.textureId;

packages/video_player/video_player_android/lib/src/messages.g.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ class CreateMessage {
138138
this.uri,
139139
this.packageName,
140140
this.formatHint,
141-
this.httpHeaders,
141+
required this.httpHeaders,
142142
});
143143

144144
String? asset;
145145
String? uri;
146146
String? packageName;
147147
String? formatHint;
148-
Map<String?, String?>? httpHeaders;
148+
Map<String?, String?> httpHeaders;
149149

150150
Object encode() {
151151
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
@@ -164,8 +164,8 @@ class CreateMessage {
164164
uri: pigeonMap['uri'] as String?,
165165
packageName: pigeonMap['packageName'] as String?,
166166
formatHint: pigeonMap['formatHint'] as String?,
167-
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)
168-
?.cast<String?, String?>(),
167+
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)!
168+
.cast<String?, String?>(),
169169
);
170170
}
171171
}

packages/video_player/video_player_android/pigeons/messages.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ class PositionMessage {
4343
}
4444

4545
class CreateMessage {
46+
CreateMessage({required this.httpHeaders});
4647
String? asset;
4748
String? uri;
4849
String? packageName;
4950
String? formatHint;
50-
Map<String?, String?>? httpHeaders;
51+
Map<String?, String?> httpHeaders;
5152
}
5253

5354
class MixWithOthersMessage {

packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
4343
@property(nonatomic, readonly) BOOL isInitialized;
4444
- (instancetype)initWithURL:(NSURL *)url
4545
frameUpdater:(FLTFrameUpdater *)frameUpdater
46-
httpHeaders:(NSDictionary<NSString *, NSString *> *)headers;
46+
httpHeaders:(nonnull NSDictionary<NSString *, NSString *> *)headers;
4747
@end
4848

4949
static void *timeRangeContext = &timeRangeContext;
@@ -57,7 +57,7 @@ - (instancetype)initWithURL:(NSURL *)url
5757
@implementation FLTVideoPlayer
5858
- (instancetype)initWithAsset:(NSString *)asset frameUpdater:(FLTFrameUpdater *)frameUpdater {
5959
NSString *path = [[NSBundle mainBundle] pathForResource:asset ofType:nil];
60-
return [self initWithURL:[NSURL fileURLWithPath:path] frameUpdater:frameUpdater httpHeaders:nil];
60+
return [self initWithURL:[NSURL fileURLWithPath:path] frameUpdater:frameUpdater httpHeaders:@{}];
6161
}
6262

6363
- (void)addObservers:(AVPlayerItem *)item {
@@ -177,7 +177,7 @@ - (void)createVideoOutputAndDisplayLink:(FLTFrameUpdater *)frameUpdater {
177177

178178
- (instancetype)initWithURL:(NSURL *)url
179179
frameUpdater:(FLTFrameUpdater *)frameUpdater
180-
httpHeaders:(NSDictionary<NSString *, NSString *> *)headers {
180+
httpHeaders:(nonnull NSDictionary<NSString *, NSString *> *)headers {
181181
NSDictionary<NSString *, id> *options = nil;
182182
if (headers != nil && [headers count] != 0) {
183183
options = @{@"AVURLAssetHTTPHeaderFieldsKey" : headers};

packages/video_player/video_player_avfoundation/ios/Classes/messages.g.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ NS_ASSUME_NONNULL_BEGIN
5959
@end
6060

6161
@interface FLTCreateMessage : NSObject
62+
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
63+
- (instancetype)init NS_UNAVAILABLE;
6264
+ (instancetype)makeWithAsset:(nullable NSString *)asset
6365
uri:(nullable NSString *)uri
6466
packageName:(nullable NSString *)packageName
6567
formatHint:(nullable NSString *)formatHint
66-
httpHeaders:(nullable NSDictionary<NSString *, NSString *> *)httpHeaders;
68+
httpHeaders:(NSDictionary<NSString *, NSString *> *)httpHeaders;
6769
@property(nonatomic, copy, nullable) NSString *asset;
6870
@property(nonatomic, copy, nullable) NSString *uri;
6971
@property(nonatomic, copy, nullable) NSString *packageName;
7072
@property(nonatomic, copy, nullable) NSString *formatHint;
71-
@property(nonatomic, strong, nullable) NSDictionary<NSString *, NSString *> *httpHeaders;
73+
@property(nonatomic, strong) NSDictionary<NSString *, NSString *> *httpHeaders;
7274
@end
7375

7476
@interface FLTMixWithOthersMessage : NSObject

packages/video_player/video_player_avfoundation/ios/Classes/messages.g.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ + (instancetype)makeWithAsset:(nullable NSString *)asset
172172
uri:(nullable NSString *)uri
173173
packageName:(nullable NSString *)packageName
174174
formatHint:(nullable NSString *)formatHint
175-
httpHeaders:(nullable NSDictionary<NSString *, NSString *> *)httpHeaders {
175+
httpHeaders:(NSDictionary<NSString *, NSString *> *)httpHeaders {
176176
FLTCreateMessage *pigeonResult = [[FLTCreateMessage alloc] init];
177177
pigeonResult.asset = asset;
178178
pigeonResult.uri = uri;
@@ -188,6 +188,7 @@ + (FLTCreateMessage *)fromMap:(NSDictionary *)dict {
188188
pigeonResult.packageName = GetNullableObject(dict, @"packageName");
189189
pigeonResult.formatHint = GetNullableObject(dict, @"formatHint");
190190
pigeonResult.httpHeaders = GetNullableObject(dict, @"httpHeaders");
191+
NSAssert(pigeonResult.httpHeaders != nil, @"");
191192
return pigeonResult;
192193
}
193194
- (NSDictionary *)toMap {

packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,35 @@ class AVFoundationVideoPlayer extends VideoPlayerPlatform {
3333

3434
@override
3535
Future<int?> create(DataSource dataSource) async {
36-
final CreateMessage message = CreateMessage();
37-
36+
String? asset;
37+
String? packageName;
38+
String? uri;
39+
String? formatHint;
40+
Map<String, String> httpHeaders = <String, String>{};
3841
switch (dataSource.sourceType) {
3942
case DataSourceType.asset:
40-
message.asset = dataSource.asset;
41-
message.packageName = dataSource.package;
43+
asset = dataSource.asset;
44+
packageName = dataSource.package;
4245
break;
4346
case DataSourceType.network:
44-
message.uri = dataSource.uri;
45-
message.formatHint = _videoFormatStringMap[dataSource.formatHint];
46-
message.httpHeaders = dataSource.httpHeaders;
47+
uri = dataSource.uri;
48+
formatHint = _videoFormatStringMap[dataSource.formatHint];
49+
httpHeaders = dataSource.httpHeaders;
4750
break;
4851
case DataSourceType.file:
49-
message.uri = dataSource.uri;
52+
uri = dataSource.uri;
5053
break;
5154
case DataSourceType.contentUri:
52-
message.uri = dataSource.uri;
55+
uri = dataSource.uri;
5356
break;
5457
}
58+
final CreateMessage message = CreateMessage(
59+
asset: asset,
60+
packageName: packageName,
61+
uri: uri,
62+
httpHeaders: httpHeaders,
63+
formatHint: formatHint,
64+
);
5565

5666
final TextureMessage response = await _api.create(message);
5767
return response.textureId;

packages/video_player/video_player_avfoundation/lib/src/messages.g.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ class CreateMessage {
138138
this.uri,
139139
this.packageName,
140140
this.formatHint,
141-
this.httpHeaders,
141+
required this.httpHeaders,
142142
});
143143

144144
String? asset;
145145
String? uri;
146146
String? packageName;
147147
String? formatHint;
148-
Map<String?, String?>? httpHeaders;
148+
Map<String?, String?> httpHeaders;
149149

150150
Object encode() {
151151
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
@@ -164,8 +164,8 @@ class CreateMessage {
164164
uri: pigeonMap['uri'] as String?,
165165
packageName: pigeonMap['packageName'] as String?,
166166
formatHint: pigeonMap['formatHint'] as String?,
167-
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)
168-
?.cast<String?, String?>(),
167+
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)!
168+
.cast<String?, String?>(),
169169
);
170170
}
171171
}

0 commit comments

Comments
 (0)