This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Stub that holds all of the values in memory | |
class StubStorage implements Storage { | |
final hash = <String, dynamic>{}; | |
@override | |
bool? getBool(String key) => hash[key] as bool?; | |
@override | |
String? getString(String key) => hash[key] as String?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Response<T> buildFailureResponse<T>( | |
String message, { | |
int code = 400, | |
http.BaseRequest? request, | |
}) { | |
final body = jsonDecode(message) as Map<String, dynamic>; | |
final error = buildBackendError(statusCode: code, body: body); | |
return Response( | |
http.Response(message, code, request: request), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Response<T> buildFailureResponse<T>( | |
String message, { | |
int code = 400, | |
http.BaseRequest? request, | |
}) { | |
final body = jsonDecode(message) as Map<String, dynamic>; | |
final error = buildBackendError(statusCode: code, body: body); | |
return Response( | |
http.Response(message, code, request: request), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Response<T> buildFailureResponse<T>( | |
String message, { | |
int code = 400, | |
http.BaseRequest? request, | |
}) { | |
final body = jsonDecode(message) as Map<String, dynamic>; | |
final error = buildBackendError(statusCode: code, body: body); | |
return Response( | |
http.Response(message, code, request: request), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group('with a success', () { | |
setUpAll(() async { | |
when(pushNotifier.requestPermissions()).thenSucceed(true); | |
when(pushNotifier.onTokenRefresh()).thenStream(fcmRefreshedToken); | |
await subject().onInit(); | |
}); | |
test('ask for push permissions', () { | |
verify(pushNotifier.requestPermissions()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// mocking the PostExpectation with a Future | |
extension FutureMock<T> on PostExpectation<Future<T>> { | |
void thenFuture(T body) { | |
thenAnswer((realInvocation) => Future.value(body)); | |
} | |
} | |
/// we use Result objet similar than a monad which returns a success, a failure, etc | |
/// this extension mocks a Result of success, failure or in order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await onErrorRetry( | |
doIt: () async { | |
await _twilioModule.setup(); | |
_analytic.track('Platform Loaded'); | |
_router.replaceTo(HomeRoute()); | |
status = status.rebuild((b) => b..isLoadingVisible = false); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef FunctionOnRetry = Function( | |
dynamic ex, | |
int retryCount, | |
int retryInMilliseconds, | |
); | |
Future<void> onErrorRetry({ | |
required Future Function() doIt, | |
required FunctionOnRetry onRetry, | |
required int maxRetries, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// this class uses Isolates.run, only available after Dart 2.19, allowing in parallel obtaining a file in bytes | |
/// then answering to its caller without blocking the UI | |
/// remember: when using isolates, the functions they call must be top level or static | |
import 'dart:isolate'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:http/http.dart' as http; | |
Future<http.Response> _fileResponse(Uri uri) async { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// this is part of a stateful widget, that uses Isolates.compute to do a heavy task, in this case download and | |
/// display an image from internet in parallel. | |
/// this will help to improve performance for our scenario when a chat messages screen should display all messages | |
class _MessagesImageState extends State<MessagesImage> { | |
@override | |
Widget build(BuildContext context) { | |
return InkWell( | |
onTap: () { | |
// onTap logic |
NewerOlder