我阅读了Flutter网站上有关平台特定插件/通道的介绍,并浏览了一些插件的简单示例,比如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?
TestDefaultBinaryMessengerBinding.instance
是可空的,因此我应该添加空值检查('?' 或 '!')。 - Fuad Rezaplugins.flutter.io
是如何衍生出来的:const channel = MethodChannel('plugins.flutter.io/package_info');
- Worik