我正在尝试在我的 android flutter 应用程序中实现 Google Sign In,但我遇到了这个问题:
当用户取消 Google 登录(点击后退按钮)时,会抛出此异常。
PlatformException (PlatformException(sign_in_canceled, com.google.android.gms.common.api.ApiException: 12501: , null))
我发现从一些较新的版本这应该是固定的,它应该返回 null 而不是异常。目前我正在使用google_sign_in: ^4.1.1
我试图将我的代码包装在 try-catch 块中或在方法上使用 .catchError() ,但没有任何帮助。
我的代码如下所示:
Future googleSign(BuildContext context) async {
final GoogleSignInAccount googleSignInAccount =
await googleSignIn.signIn().catchError((onError) => print(onError));
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final AuthResult authResult = await _auth.signInWithCredential(credential);
return authResult.user.uid;
}
Run Code Online (Sandbox Code Playgroud)
你有什么想法,如何处理这个异常?谢谢。
我想在我的 Flutter 应用程序中实现某种后台作业/检查,但我注意到 iOS 上有这种奇怪的行为。
当我启动这个计时器并且仍在应用程序中时,一切正常,但是当我从应用程序返回主屏幕时,此回调执行五次然后停止。另一方面,在 Android 上,即使我在主屏幕上,它也会一直运行。
我在 info.plist 中添加了这个“权限”,但经过几次尝试后它仍然停止。
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
<string>remote-notification</string>
</array>
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个包(https://pub.dev/packages/workmanager),但对我不起作用。
这是我应该执行的函数
Timer.periodic(const Duration(seconds: 30), (_) async {
var parkingLots = await DataService().getFreePlaces();
if (parkingLots[parkingLotId] == 0) {
print("full");
} else {
print("job is running");
}
print(parkingLots[parkingLotId]);
});
Run Code Online (Sandbox Code Playgroud)
基本上,它应该每 30 秒检查停车场是否有一些空闲位置,如果没有,它应该向用户发送通知。
您知道如何使这项工作有效吗?或者您有什么建议如何做到这一点?
谢谢
我只是想问你,flutter 中的 Google Admob 插件是否不会影响应用程序性能,因为在我的虚拟设备上,在我实现广告横幅后,它会变得有点滞后。
它们会在后台自动更新,我不知道它们是否没有堆叠在一起或类似的东西。
这是我的代码:
@override
void initState() {
FirebaseAdMob.instance.initialize(appId: "ca-app-pub-...");
targetingInfo = MobileAdTargetingInfo(
nonPersonalizedAds: false,
);
banner = BannerAd(
adUnitId: "ca-app-pub-...",
size: AdSize.banner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);
banner
..load()
..show(
anchorOffset: 0.0,
horizontalCenterOffset: 10.0,
anchorType: AnchorType.top,
);
super.initState();
}
@override
void dispose() {
banner.dispose();
super.dispose();
}
Run Code Online (Sandbox Code Playgroud)
感谢您的建议。
我正在尝试将格式为“23.1.2020”的字符串解析为 DateTime 对象,但对我来说没有任何效果。我尝试使用一些包,如 intl 或 date_format,但这些都不能完成这项工作。
DateTime todayDate = DateTime.parse("12.04.2020");
formatDate(todayDate, [yyyy, '/', mm, '/', dd, ' ', hh, ':', nn, ':', ss, ' ', am])
Run Code Online (Sandbox Code Playgroud)
你有什么想法,如何解析这个?
我试图在流构建器中设置值,但是当我想使用 setState 函数设置值时,出现此错误。
在构建期间调用 setState() 或 markNeedsBuild()。
这是我的截图
int countRecent = 0;
...
return StreamBuilder<Object>(
stream: Data(uid: user.uid).getTrips,
builder: (context, snapshot) {
dynamic items = snapshot.data;
setState(() => countRecent = items.length);
}
...
Text(
"$countRecent",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w900,
fontSize: 43,
letterSpacing: 0.2,
fontFamily: "VarelaRound",
),
),
Run Code Online (Sandbox Code Playgroud)
基本上,我想要的是每次文档更改(或者更确切地说该文档的长度)时更新此变量。
你有什么想法?
我正在尝试在我的 flutter 应用程序中实现黑暗模式,但我不知道我错过了什么,但它在 iOS 上不起作用。我设法在 Android 上运行得很好,但当我打印时,WidgetsBinding.instance.window.platformBrightness仍然有光,当黑暗模式打开时。
当我设置 themeMode: ThemeMode.dark - 深色模式正常工作时,问题出在自动检测上。
另外,当我运行新的空白项目时,深色模式工作正常。但在我构建的应用程序中,它不起作用。即使themeMode设置为ThemeMode.system:
themeMode: ThemeMode.system,
theme: ThemeData(
accentColor: darkBlue,
cursorColor: red,
primaryColor: Colors.white,
brightness: Brightness.light,
),
darkTheme: ThemeData(
accentColor: Colors.white,
cursorColor: red,
primaryColor: Colors.white,
brightness: Brightness.dark,
),
Run Code Online (Sandbox Code Playgroud)
您有什么想法吗?可能出了什么问题,或者您有什么建议吗?
Flutter 版本:1.12.13-hotfix.9和 iOS 版本:iPhone SE 模拟器 - iOS 13.3
多谢。
我正在尝试将管道中构建的映像推送到 Docker 注册表,并且我的映像上有两个标签(latest和commit hash),但是当使用该命令时docker push --all-tags registry.gitlab.com/group/image-name,它不起作用,并且出现此错误:
未知标志:--all-tags
我正在使用最新版本的 docker,GitLab CI/CD 阶段定义如下
Build Docker Image:
stage: Build Docker Image
image: docker:stable
needs: ["Build & Test App"]
services:
- docker:dind
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" "$CI_REGISTRY_IMAGE:latest"
- docker push --all-tags "$CI_REGISTRY_IMAGE"
Run Code Online (Sandbox Code Playgroud)
当我在本地计算机上尝试时,似乎这个标志是已知的并且它可以工作。你知道,可能是什么问题吗?多谢。