我想验证是否使用不包含特定字段的对象调用了模拟 API 。
expect(api.method).toBeCalledWith(expectedObject);
Run Code Online (Sandbox Code Playgroud)
由于api.method调用的实际参数可以是expectedObject此测试的子集,如果actualObject包含更多字段(其中可能是特定字段),则此测试也会通过。
如何以某种方式重写测试,如果actualObject不等于,则测试失败expectedObject?
我在容器内的墨水(给它一个边框)内有一个图标按钮。但是,边框不可见,因为它被容器颜色覆盖。
在容器内显示带有彩色背景的 IconButton 的最佳方式是什么?
工作示例:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.pink,
child: Center(
child: Ink(
decoration: const ShapeDecoration(
color: Colors.black,
shape: CircleBorder(),
),
child: IconButton(
icon: Icon(Icons.android),
color: Colors.white,
onPressed: () {},
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud) 我想将数据传递到另一个屏幕。根据使用命名路由时的文档,我需要使用参数并使用:
Navigator.pushNamed(
context,
NextScreen.route,
arguments: NextScreenArgs("pew"),
);
Run Code Online (Sandbox Code Playgroud)
然而,同样的(?)可以通过使用来完成:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NextScreen("pew"),
),
);
Run Code Online (Sandbox Code Playgroud)
使用有什么区别或优势pushNamed吗?
以下(简化)代码
type Category = {
id: string,
name: string,
};
type Option = {
id: string,
name: string,
isSelected: boolean,
};
const options = categories.map((c: Category): Option => ({
isSelected: true,
...c,
}));
Run Code Online (Sandbox Code Playgroud)
产生错误:
Flow:无法传播对象文字,因为 Flow 无法确定对象文字 [1] 的类型。
Category[2] 是不准确的,因此它可能包含isSelected与isSelected对象字面量 [1] 中的定义冲突的类型。尝试使Category[2] 精确。
我错过了什么?