Fixed null safety

This commit is contained in:
thomashii 2021-03-21 09:40:22 +08:00
parent a7c2a0d3dc
commit cb56b31d10
11 changed files with 30 additions and 30 deletions

View file

@ -10,9 +10,9 @@
* Updated angel_container to 3.0.0 * Updated angel_container to 3.0.0
* Added merge_map and updated to 2.0.0 * Added merge_map and updated to 2.0.0
* Added mock_request and updated to 2.0.0 * Added mock_request and updated to 2.0.0
* Updated angel_framework to 4.0.0 (Revisit TODO) * Updated angel_framework to 4.0.0 (Revisit TODO, Fix failed tests)
* Updated angel_auth to 4.0.0 * Updated angel_auth to 4.0.0 (In progress)
* Updated angel_configuration to 4.0.0 (todo) * Updated angel_configuration to 4.0.0 (In progress)
# 3.0.0 (Non NNBD) # 3.0.0 (Non NNBD)
* Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0" * Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0"

View file

@ -128,13 +128,13 @@ class Controller {
var injection = preInject(reflectedMethod!, reflector); var injection = preInject(reflectedMethod!, reflector);
if (exposeDecl?.allowNull?.isNotEmpty == true) { if (exposeDecl.allowNull.isNotEmpty == true) {
injection.optional?.addAll(exposeDecl.allowNull); injection.optional.addAll(exposeDecl.allowNull);
} }
// If there is no path, reverse-engineer one. // If there is no path, reverse-engineer one.
var path = exposeDecl.path; var path = exposeDecl.path;
var httpMethod = exposeDecl.method ?? 'GET'; var httpMethod = exposeDecl.method;
if (path == null) { if (path == null) {
// Try to build a route path by finding all potential // Try to build a route path by finding all potential
// path segments, and then joining them. // path segments, and then joining them.

View file

@ -471,7 +471,7 @@ class HookedService<Id, Data, T extends Service<Id, Data>>
HookedServiceEvent<Id, Data, T> event, HookedServiceEvent<Id, Data, T> event,
[HookedServiceEventListener<Id, Data, T>? callback]) { [HookedServiceEventListener<Id, Data, T>? callback]) {
Future? f; Future? f;
if (callback != null && event?._canceled != true) { if (callback != null && event._canceled != true) {
f = Future.sync(() => callback(event)); f = Future.sync(() => callback(event));
} }
f ??= Future.value(); f ??= Future.value();
@ -560,7 +560,7 @@ class HookedServiceEventDispatcher<Id, Data, T extends Service<Id, Data>> {
/// Fires an event, and returns it once it is either canceled, or all listeners have run. /// Fires an event, and returns it once it is either canceled, or all listeners have run.
Future<HookedServiceEvent<Id, Data, T>> _emit( Future<HookedServiceEvent<Id, Data, T>> _emit(
HookedServiceEvent<Id, Data, T> event) { HookedServiceEvent<Id, Data, T> event) {
if (event?._canceled == true || event == null || listeners.isEmpty) { if (event._canceled == true || listeners.isEmpty) {
return Future.value(event); return Future.value(event);
} }

View file

@ -45,8 +45,6 @@ class HostnameRouter {
}); });
} }
apps ??= {};
creators ??= {};
apps = _parseMap(apps); apps = _parseMap(apps);
creators = _parseMap(creators); creators = _parseMap(creators);
var patterns = apps.keys.followedBy(creators.keys).toSet().toList(); var patterns = apps.keys.followedBy(creators.keys).toSet().toList();

View file

@ -26,7 +26,7 @@ resolveInjection(requirement, InjectionRequest? injection, RequestContext req,
ResponseContext res, bool throwOnUnresolved, ResponseContext res, bool throwOnUnresolved,
[Container? container]) async { [Container? container]) async {
var propFromApp; var propFromApp;
container ??= req?.container ?? res?.app?.container; container ??= req.container ?? res.app?.container;
if (requirement == RequestContext) { if (requirement == RequestContext) {
return req; return req;

View file

@ -122,8 +122,7 @@ class Parameter {
/// Obtains a value for this parameter from a [RequestContext]. /// Obtains a value for this parameter from a [RequestContext].
getValue(RequestContext req) { getValue(RequestContext req) {
if (cookie?.isNotEmpty == true) { if (cookie?.isNotEmpty == true) {
return req.cookies!.firstWhere((c) => c.name == cookie)?.value ?? return req.cookies!.firstWhere((c) => c.name == cookie).value;
defaultValue;
} }
if (header?.isNotEmpty == true) { if (header?.isNotEmpty == true) {
return req.headers!.value(header!) ?? defaultValue; return req.headers!.value(header!) ?? defaultValue;

View file

@ -24,7 +24,7 @@ RequestHandler chain(Iterable<RequestHandler> handlers) {
Future Function()? runPipeline; Future Function()? runPipeline;
for (var handler in handlers) { for (var handler in handlers) {
if (handler == null) break; //if (handler == null) break;
if (runPipeline == null) { if (runPipeline == null) {
runPipeline = () => Future.sync(() => handler(req, res)); runPipeline = () => Future.sync(() => handler(req, res));
@ -108,7 +108,10 @@ class Routable extends Router<RequestHandler?> {
} }
final handlerSequence = <RequestHandler>[]; final handlerSequence = <RequestHandler>[];
handlerSequence.addAll(middleware as Iterable<FutureOr<dynamic>? Function(RequestContext<dynamic>, ResponseContext<dynamic>)>? ?? []); handlerSequence.addAll(middleware as Iterable<
FutureOr<dynamic>? Function(
RequestContext<dynamic>, ResponseContext<dynamic>)>? ??
[]);
handlerSequence.addAll(handlers); handlerSequence.addAll(handlers);
return super.addRoute(method, path.toString(), handler, return super.addRoute(method, path.toString(), handler,

View file

@ -159,7 +159,7 @@ class Angel extends Routable {
'This route will be ignored, and no requests will ever reach it.'); 'This route will be ignored, and no requests will ever reach it.');
} }
return super.addRoute(method, path, handler, middleware: middleware ?? []); return super.addRoute(method, path, handler, middleware: middleware);
} }
@override @override
@ -225,21 +225,21 @@ class Angel extends Routable {
_flattened!.dumpTree( _flattened!.dumpTree(
callback: callback, callback: callback,
header: header?.isNotEmpty == true header: header.isNotEmpty == true
? header ? header
: (environment.isProduction : (environment.isProduction
? 'Dumping flattened route tree:' ? 'Dumping flattened route tree:'
: 'Dumping route tree:'), : 'Dumping route tree:'),
tab: tab ?? ' '); tab: tab);
} else { } else {
super.dumpTree( super.dumpTree(
callback: callback, callback: callback,
header: header?.isNotEmpty == true header: header.isNotEmpty == true
? header ? header
: (environment.isProduction : (environment.isProduction
? 'Dumping flattened route tree:' ? 'Dumping flattened route tree:'
: 'Dumping route tree:'), : 'Dumping route tree:'),
tab: tab ?? ' '); tab: tab);
} }
} }
@ -319,7 +319,7 @@ class Angel extends Routable {
/// Runs with DI, and *always* reflects. Prefer [runContained]. /// Runs with DI, and *always* reflects. Prefer [runContained].
Future runReflected(Function handler, RequestContext req, ResponseContext res, Future runReflected(Function handler, RequestContext req, ResponseContext res,
[Container? container]) { [Container? container]) {
container ??= req?.container ?? res?.app?.container; container ??= req.container ?? res.app?.container;
var h = handleContained( var h = handleContained(
handler, handler,
_preContained[handler] = preInject(handler, container!.reflector), _preContained[handler] = preInject(handler, container!.reflector),

View file

@ -9,11 +9,11 @@ export 'http_response_context.dart';
/// Boots a shared server instance. Use this if launching multiple isolates. /// Boots a shared server instance. Use this if launching multiple isolates.
Future<HttpServer> startShared(address, int port) => Future<HttpServer> startShared(address, int port) =>
HttpServer.bind(address ?? '127.0.0.1', port ?? 0, shared: true); HttpServer.bind(address ?? '127.0.0.1', port, shared: true);
Future<HttpServer> Function(dynamic, int) startSharedSecure( Future<HttpServer> Function(dynamic, int) startSharedSecure(
SecurityContext securityContext) { SecurityContext securityContext) {
return (address, int port) => HttpServer.bindSecure( return (address, int port) => HttpServer.bindSecure(
address ?? '127.0.0.1', port ?? 0, securityContext, address ?? '127.0.0.1', port, securityContext,
shared: true); shared: true);
} }

View file

@ -60,9 +60,9 @@ class HttpResponseContext extends ResponseContext<HttpResponse> {
return __allowedEncodings ??= correspondingRequest!.headers! return __allowedEncodings ??= correspondingRequest!.headers!
.value('accept-encoding') .value('accept-encoding')
?.split(',') ?.split(',')
?.map((s) => s.trim()) .map((s) => s.trim())
?.where((s) => s.isNotEmpty) .where((s) => s.isNotEmpty)
?.map((str) { .map((str) {
// Ignore quality specifications in accept-encoding // Ignore quality specifications in accept-encoding
// ex. gzip;q=0.8 // ex. gzip;q=0.8
if (!str.contains(';')) return str; if (!str.contains(';')) return str;

View file

@ -119,9 +119,9 @@ class Http2ResponseContext extends ResponseContext<ServerTransportStream> {
return __allowedEncodings ??= correspondingRequest!.headers! return __allowedEncodings ??= correspondingRequest!.headers!
.value('accept-encoding') .value('accept-encoding')
?.split(',') ?.split(',')
?.map((s) => s.trim()) .map((s) => s.trim())
?.where((s) => s.isNotEmpty) .where((s) => s.isNotEmpty)
?.map((str) { .map((str) {
// Ignore quality specifications in accept-encoding // Ignore quality specifications in accept-encoding
// ex. gzip;q=0.8 // ex. gzip;q=0.8
if (!str.contains(';')) return str; if (!str.contains(';')) return str;