mirror of
https://github.com/flutter/samples.git
synced 2025-11-12 15:58:32 +00:00
move experimental/form_app to root of project (#623)
This allows us to reference this sample from other places. See https://github.com/flutter/flutter/pull/70321 for more context.
This commit is contained in:
31
form_app/lib/src/http/mock_client.dart
Normal file
31
form_app/lib/src/http/mock_client.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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 'package:http/http.dart' as http;
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
class MockClient extends Mock implements http.Client {
|
||||
MockClient() {
|
||||
when(post('https://example.com/signin', body: anyNamed('body')))
|
||||
.thenAnswer((answering) {
|
||||
var body = answering.namedArguments[Symbol('body')];
|
||||
|
||||
if (body != null && body is String) {
|
||||
var decodedJson = json.decode(body);
|
||||
|
||||
if (decodedJson['email'] == 'root' &&
|
||||
decodedJson['password'] == 'password') {
|
||||
return Future.value(http.Response('', 200));
|
||||
}
|
||||
}
|
||||
|
||||
return Future.value(http.Response('', 401));
|
||||
});
|
||||
|
||||
when(post('https://example.com/signout'))
|
||||
.thenAnswer((_) => Future.value(http.Response('', 401)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user