mirror of https://github.com/flutter/samples.git
Migrate form_app to null safety (#925)
parent
e2e2713986
commit
d3c6253f85
@ -1,33 +1,18 @@
|
|||||||
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
|
||||||
// for details. All rights reserved. Use of this source code is governed by a
|
|
||||||
// BSD-style license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:http/testing.dart';
|
||||||
|
|
||||||
class MockClient extends Mock implements http.Client {
|
|
||||||
MockClient() {
|
|
||||||
when(post('https://example.com/signin',
|
|
||||||
body: anyNamed('body'), headers: anyNamed('headers')))
|
|
||||||
.thenAnswer((answering) {
|
|
||||||
dynamic body = answering.namedArguments[const Symbol('body')];
|
|
||||||
|
|
||||||
if (body != null && body is String) {
|
// Set up a mock HTTP client.
|
||||||
var decodedJson = Map<String, dynamic>.from(
|
final http.Client mockClient = MockClient(_mockHandler);
|
||||||
json.decode(body) as Map<String, dynamic>);
|
|
||||||
|
|
||||||
if (decodedJson['email'] == 'root' &&
|
Future<http.Response> _mockHandler(http.Request request) async {
|
||||||
decodedJson['password'] == 'password') {
|
var decodedJson = Map<String, dynamic>.from(
|
||||||
return Future.value(http.Response('', 200));
|
json.decode(request.body) as Map<String, dynamic>);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Future.value(http.Response('', 401));
|
if (decodedJson['email'] == 'root' && decodedJson['password'] == 'password') {
|
||||||
});
|
return http.Response('', 200);
|
||||||
|
|
||||||
when(post('https://example.com/signout'))
|
|
||||||
.thenAnswer((_) => Future.value(http.Response('', 401)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return http.Response('', 401);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue