Jonny Borges
Committed by GitHub

Merge pull request #2456 from shawon1fb/debouncer_null_safe

Debouncer null safe
@@ -7,7 +7,9 @@ import '../status/http_status.dart'; @@ -7,7 +7,9 @@ import '../status/http_status.dart';
7 7
8 class GraphQLResponse<T> extends Response<T> { 8 class GraphQLResponse<T> extends Response<T> {
9 final List<GraphQLError>? graphQLErrors; 9 final List<GraphQLError>? graphQLErrors;
  10 +
10 GraphQLResponse({T? body, this.graphQLErrors}) : super(body: body); 11 GraphQLResponse({T? body, this.graphQLErrors}) : super(body: body);
  12 +
11 GraphQLResponse.fromResponse(Response res) 13 GraphQLResponse.fromResponse(Response res)
12 : graphQLErrors = null, 14 : graphQLErrors = null,
13 super( 15 super(
@@ -31,6 +33,26 @@ class Response<T> { @@ -31,6 +33,26 @@ class Response<T> {
31 this.body, 33 this.body,
32 }); 34 });
33 35
  36 + Response<T> copyWith({
  37 + Request? request,
  38 + int? statusCode,
  39 + Stream<List<int>>? bodyBytes,
  40 + String? bodyString,
  41 + String? statusText,
  42 + Map<String, String>? headers,
  43 + T? body,
  44 + }) {
  45 + return Response<T>(
  46 + request: request ?? this.request,
  47 + statusCode: statusCode ?? this.statusCode,
  48 + bodyBytes: bodyBytes ?? this.bodyBytes,
  49 + bodyString: bodyString ?? this.bodyString,
  50 + statusText: statusText ?? this.statusText,
  51 + headers: headers ?? this.headers,
  52 + body: body ?? this.body,
  53 + );
  54 + }
  55 +
34 /// The Http [Request] linked with this [Response]. 56 /// The Http [Request] linked with this [Response].
35 final Request? request; 57 final Request? request;
36 58
@@ -9,14 +9,14 @@ import 'dart:async'; @@ -9,14 +9,14 @@ import 'dart:async';
9 /// delayed( () => print( 'called after 1 sec' )); 9 /// delayed( () => print( 'called after 1 sec' ));
10 /// ``` 10 /// ```
11 class Debouncer { 11 class Debouncer {
12 - final Duration? delay; 12 + final Duration delay;
13 Timer? _timer; 13 Timer? _timer;
14 14
15 - Debouncer({this.delay}); 15 + Debouncer({required this.delay});
16 16
17 void call(void Function() action) { 17 void call(void Function() action) {
18 _timer?.cancel(); 18 _timer?.cancel();
19 - _timer = Timer(delay!, action); 19 + _timer = Timer(delay, action);
20 } 20 }
21 21
22 /// Notifies if the delayed call is active. 22 /// Notifies if the delayed call is active.