我对Flutter很陌生。有没有办法通过网络视图登录到我们的应用程序?
例如,在第一页中有一个我们可以登录的Web视图。登录后,该应用程序将带我们进入第二页,我们可以在其中执行其他操作。
我正在使用ModalProgressHud来显示微调器,同时它正在等待服务器的回答。我想测试当用户点击按钮时,CircularProgressIndicator显示。我的问题是pumpAndSettle()遗嘱会因此而超时CircularProgressIndicator,我认为,它会不断自我重建。关于如何测试 a 是否存在的任何建议CircularProgressIndicator?这是我的测试:
testWidgets(
'Should show a CircularProgressIndicator while it tries to login', (WidgetTester tester) async {
await (tester.pumpWidget(
generateApp(LoginView())
));
await tester.pumpAndSettle();
await tester.tap(find.byType(FlatButton));
await tester.pumpAndSettle();
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
Run Code Online (Sandbox Code Playgroud) 我试图测试这个功能
UserApi createUserApi(String url, String username, String password) {
UserApi userApi = new UserApi(base: route(url), serializers: repo);
userApi.base.basicAuth('$username', '$password');
return userApi;
}
Run Code Online (Sandbox Code Playgroud)
基本上,测试是将这个函数的结果与它的“手动组合”进行比较,期望得到相同的结果。但它没有:
String username = "asd";
String password = "asd";
UserApi userApiTest = new UserApi(base: route("asd"), serializers: repo);
userApiTest.base.basicAuth('$username', '$password');
test("UserApi creation", () {
UserApi userApi = _presenter.createUserApi("asd", "asd", "asd");
expect(userApi, userApiTest);
});
Run Code Online (Sandbox Code Playgroud)
结果总是:
Expected: <Instance of 'UserApi'>
Actual: <Instance of 'UserApi'>
Run Code Online (Sandbox Code Playgroud)
他们为什么不同?在调试中,每个属性都是相同的。
我正在尝试测试此功能:
void store(String x, String y) async {
Map<String, dynamic> map = {
'x': x,
'y': y,
};
var jsonString = json.encode(map);
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('fileName', jsonString);
}
Run Code Online (Sandbox Code Playgroud)
我看到我可以用
const MethodChannel('plugins.flutter.io/shared_preferences')
.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'getAll') {
return <String, dynamic>{}; // set initial values here if desired
}
return null;
});
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何使用,特别是在我的情况下。
I\xc2\xb4m 使用 bloc 模式,现在我来测试 UI。我的问题是:如何模拟流?\n这是我的代码:\n我向 RootPage 类提供一个可选的 mockBloc 值,如果该 mockBloc 不为 null,我会将其设置为实际的 _bloc
\n\nclass RootPage extends StatefulWidget {\n\n final loggedOut;\n final mockBlock;\n RootPage(this.loggedOut, {this.mockBlock});\n\n @override\n _RootPageState createState() => _RootPageState();\n}\n\n\nclass _RootPageState extends State<RootPage> {\n\n LoginBloc _bloc;\n\n @override\n void initState() {\n super.initState();\n if (widget.mockBlock != null)\n _bloc = widget.mockBlock;\n else\n _bloc = new LoginBloc();\n if (widget.loggedOut == false)\n _bloc.startLoad.add(null);\n }\n\n ...\n\n @override\n Widget build(BuildContext context) {\n return StreamBuilder(\n stream: _bloc.load,\n builder: (context, snapshot) {\n if (snapshot.hasData) {\n return Column(\n children: <Widget>\n …Run Code Online (Sandbox Code Playgroud) 我正在使用https://pub.dartlang.org/packages/logging,但它没有在我的日志中显示任何内容。这是我的代码:
class Test {
final Logger log = new Logger('testLogger');
Future<String> join() async {
try {
return await func();
} on Exception catch (e) {
log.severe('access denied!');
return null;
}
}
Run Code Online (Sandbox Code Playgroud) 我想知道通过集团的最佳方式。我读到了 bloc 提供者,但是使用它们与仅在构造函数中传递 bloc 之间有什么区别,例如:
ExampleView X = ExampleView(bloc,...)
Run Code Online (Sandbox Code Playgroud)
实际上,我发现这种方式更易于测试,也是保持代码更清晰的更好方式。例如,如果我有更多的块,可能会发生这样的事情:
XBlocProvider(
bloc: XBloc,
child: YBlocProvider(
bloc: Y,
child: ZBlocProvider...
)
Run Code Online (Sandbox Code Playgroud)
或者也许这只是我缺乏知识。那么,有哪些好处呢?
我有一个必须采用自定义小部件的课程。这个可以有两种不同的实现,所以我想有一个抽象类作为接口,并创建两个扩展抽象类的其他类。所以我有:
abstract class ICustomWidget extends StatelessWidget{}
class A extends ICustomWidget{
@override
Widget build(BuildContext context) =>
//Implementation
}
class B extends ICustomWidget {
@override
Widget build(BuildContext context) =>
//Implementation
}
Run Code Online (Sandbox Code Playgroud)
我想问一下这是正确的方法还是有另一种方法。谢谢
我想使用二进制文件上传文件,如截图所示:
到目前为止,我只有:
save() async {
http.put(url,headers:headers, body: );
Run Code Online (Sandbox Code Playgroud) 使用 Vue-CLI,我能够生成一份报告来分析包内容,如下所示:
`npm run build -- --report`
Run Code Online (Sandbox Code Playgroud)
我现在正在切换到 Vite,我想知道是否有类似的命令可以创建相同的报告。