小编Mol*_*0ko的帖子

Integration_test包可以与webview交互吗?

我使用integration_test包在Dart上为iOS和Android平台编写UI测试。我的应用程序中还有一个网络视图,显示带有文本字段的登录页面。我使用webview_flutter来实现。

有谁知道如果tester可以在集成测试中与我的 webview 交互?我可以在网页上找到一个文本字段并在其中输入文本吗?

我想编写这样的测试代码,但是对于 webview:

testWidgets('Authorization test', (tester) async {
  ...
  await tester.enterText(find.byKey(Key('login_text_field')), 'login');
  await tester.enterText(find.byKey(Key('password_text_field')), 'password');
  await tester.tap(find.byKey(Key('sign_in_button')));
  await tester.pumpAndSettle();
}
Run Code Online (Sandbox Code Playgroud)

以下是网页内容:

在此输入图像描述

webview flutter flutter-test

11
推荐指数
1
解决办法
3052
查看次数

我可以在 pubspec.yaml 中使用环境变量吗?

我的 Flutter 移动应用项目中有来自 GitLab 的私有依赖项。它是在 git 存储库链接中指定的,如果我使用 ssh,pubspec.yaml我可以成功运行(我已经生成了 ssh 密钥并将其添加到我的 gitlab 帐户)pub get

  my_private_package:
    git:
      url: ssh://git@************/my_private_package.git
Run Code Online (Sandbox Code Playgroud)

现在我想使用 AppCenter 构建我的应用程序并部署到商店。在 AppCenter 构建阶段不可能使用 ssh 密钥,因此我看到的唯一可行的解​​决方案是使用GitLab 部署令牌作为环境变量来从 AppCenter 计算机访问我的私有包。访问存储库的 Git 链接变为:

  my_private_package:
    git:
      url: https://gitlab+deploy-token-1:${DEPLOY_TOKEN}@************/my_private_package.git
Run Code Online (Sandbox Code Playgroud)

现在,据我了解, pubspec 无法以DEPLOY_TOKEN这种方式解析环境变量。pub get完成时出现错误:

Git error. Command: `git clone --mirror https://gitlab+deploy-token-1:******@*******/my_private_package.git /Users/***/Library/flutter/.pub-cache/git/cache/my_private_package***`
stdout:                                                                 
stderr: Cloning into bare repository '/Users/***/Library/flutter/.pub-cache/git/cache/my_private_package***'...
remote: HTTP Basic: Access denied                                       
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for …
Run Code Online (Sandbox Code Playgroud)

continuous-integration environment-variables dart flutter pubspec

7
推荐指数
1
解决办法
2026
查看次数

当应用程序处于后台时,来自 iOS 推送通知操作的 Http 请求

我的 iOS 应用程序可以通过操作按钮接收推送通知:

使用操作按钮推送通知

点击按钮通过 UrlSession 和数据任务发送 post http 请求。当应用程序暂停或未运行时,它可以很好地工作。但当应用程序处于后台时,例如当用户刚刚从底部向上滑动(或按下主页按钮)时,它不起作用。推送操作会处理,但 http 请求不会发送。

从我的 iPhone 的控制台 os_logs 中,我看到 UrlSession 无法从后台建立连接并抛出错误 Code=-1005“网络连接丢失。”。我一杀掉应用程序就可以了。我尝试了不同的 url 会话配置、后台 url 会话、后台任务,但没有任何效果。我发现的唯一解决方法是使用exit(0)fromapplicationDidEnterBackground方法,但强烈不建议以编程方式终止应用程序。

问题:当应用程序处于后台时,如何通过推送通知操作建立 http 连接?

我的代码:

class NotificationService: NSObject, UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        // notification processing if app is in foreground
        ...
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let requestId = String(describing: response.notification.request.content.userInfo["requestId"] …
Run Code Online (Sandbox Code Playgroud)

background-process apple-push-notifications ios swift

2
推荐指数
1
解决办法
2063
查看次数

如何检查字符串是否同时包含大写和小写字符

我需要验证用户输入的密码,并检查密码是否在 Dart 中至少包含一个大写和一个小写字符。

我写了这个字符串扩展:

extension StringValidators on String {
  bool containsUppercase() {
    // What code should be here?
  }

  bool containsLowercase() {
    // What code should be here?
  }
}
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

final text = passwordTextController.text;
final isValid = text.containsUppercase() && text.containsLowercase();
Run Code Online (Sandbox Code Playgroud)

有没有用于此目的的正则表达式?或者它应该是简单的算法?请帮我找出优雅的方法。谢谢!

string validation dart flutter

2
推荐指数
2
解决办法
1万
查看次数