【发布时间】:2017-10-09 09:54:11
【问题描述】:
我在 Flutter 网站上阅读了 introduction to platform-specific plugins/channels 并浏览了一些简单的插件示例,例如 url_launcher:
// Copyright 2017 The Chromium Authors. 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:async';
import 'package:flutter/services.dart';
const _channel = const MethodChannel('plugins.flutter.io/url_launcher');
/// Parses the specified URL string and delegates handling of it to the
/// underlying platform.
///
/// The returned future completes with a [PlatformException] on invalid URLs and
/// schemes which cannot be handled, that is when [canLaunch] would complete
/// with false.
Future<Null> launch(String urlString) {
return _channel.invokeMethod(
'launch',
urlString,
);
}
在小部件测试或集成测试中,我如何模拟或存根通道,这样我就不必依赖真实设备(运行 Android 或 iOS),例如实际启动 URL?
【问题讨论】:
标签: android ios unit-testing dart flutter