File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'package:flutter/services.dart' ;
2+
3+ class MethodChannelMock {
4+ final MethodChannel methodChannel;
5+ final String method;
6+ final dynamic result;
7+ final Duration delay;
8+
9+ MethodChannelMock ({
10+ required String channelName,
11+ required this .method,
12+ this .result,
13+ this .delay = Duration .zero,
14+ }) : methodChannel = MethodChannel (channelName) {
15+ methodChannel.setMockMethodCallHandler (_handler);
16+ }
17+
18+ Future _handler (MethodCall methodCall) async {
19+ if (methodCall.method != method) {
20+ throw MissingPluginException ('No implementation found for method '
21+ '$method on channel ${methodChannel .name }' );
22+ }
23+
24+ return Future .delayed (delay, () {
25+ if (result is Exception ) {
26+ throw result;
27+ }
28+
29+ return Future .value (result);
30+ });
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments