我目前正在尝试将 Provider 作为状态管理解决方案,我知道它不能在 initState 函数中使用。
我见过的所有示例都ChangeNotifier根据用户操作(例如,用户单击按钮)调用派生类中的方法,但是如果我需要在初始化状态时调用方法怎么办?
动机:创建一个加载资产(异步)并显示进度的屏幕
ChangeNotifier该类的示例(不能add从调用initState):
import 'package:flutter/foundation.dart';
class ProgressData extends ChangeNotifier {
double _progress = 0;
double get progress => _progress;
void add(double dProgress) {
_progress += dProgress;
notifyListeners();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在两个屏幕之间转换文本小部件(使用英雄小部件)。我希望文本小部件在这两个屏幕之间更改其样式(比如说 FontSize)。
实现它会导致奇怪的行为:文本不会平滑地改变其大小,而是有生涩的动画......
关于如何正确实施它有什么想法吗?
过去两天我一直试图将我的游戏版本上传到AppStore.
我一直收到以下错误:
错误ITMS-90164:"无效的代码签名权利.应用程序包签名中的权利与供应配置文件中包含的权限不匹配.根据供应配置文件,捆绑包含不允许的密钥值:'true ''Payload/Game.app/Game'中的关键'get-task-allow'"
ERROR ITMS-90179:"无效的代码签名.可执行文件'Payload/Game.app/Game'必须使用配置文件中包含的证书进行签名."
使用FlashDevelop,Air 19.0(自AIR 20.0中的最新问题 - 21.0).
我没有在我的application.xml中包含get-task-allow标记,我已经加倍检查我的证书,配置配置文件等,甚至重新创建它们 - 但似乎没有任何东西可以使它工作......
感觉像证书问题,但我找不到问题.
在 Flutter 中,尝试使用NetworkImage从(开发)服务器(没有证书的 HTTPS)加载图像- 导致抛出异常:客户端中的握手错误(操作系统错误:CERTIFICATE_VERIFY_FAILED:ok(handshake.cc:355))
是否有解决方法,类似于它在HTTPClient 中的完成方式?httpClient.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
我正在尝试为我的 Flutter 应用程序使用 in_app_purchase 插件(https://pub.dev/packages/in_app_purchase)。
调用 queryProductDetails(ids) 工作得很好,但是在调用 queryPastPurchases() 时我得到以下异常:
PlatformException (PlatformException(storekit_no_receipt, Cannot find receipt for the current main bundle., null))
Run Code Online (Sandbox Code Playgroud)
似乎这是异常的来源:https : //github.com/flutter/plugins/blob/master/packages/in_app_purchase/ios/Classes/FIAPReceiptManager.m
值得一提的是:我已经在 App-Store-Connect 中设置了一个 IAP。此 IAP 尚未发送给 Apple 批准。应用程序正在开发中,使用 TestFlight 和 beta 测试人员进行测试。
另一个问题是,这个异常不会在 try-catch 语句中出现(请参阅下面的代码),而只会在检查 VSCode 中的“所有异常”选项时由环境引起...
在模拟器和真实设备上测试。
[更新]:在插件的objective-c代码中添加了断点,看到receiptURL指向“sandboxReceipt”。所以也许是因为我不使用沙箱用户?
Future<void> _getPastPurchases() async {
try {
final QueryPurchaseDetailsResponse response = await InAppPurchaseConnection.instance.queryPastPurchases();
if (response.error != null) {
// Handle the error
print(response.error.toString());
}
print('response = ' + response.toString());
for (PurchaseDetails purchase in response.pastPurchases) { …Run Code Online (Sandbox Code Playgroud) 在为 Android 编译我的 Flutter 移动应用程序(安装 APK)时,我收到以下警告:
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Note: /Users/ez/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.12.6/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/ez/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.12.6/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/ez/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.4.0+6/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)
StackOverflow 上有很多这样的问题,每个问题都用一组不同的插件版本来回答。
我做了什么: 1. 我已经将我的插件更新到最新版本:
dependencies:
flutter:
sdk: flutter …Run Code Online (Sandbox Code Playgroud) 以下代码会导致错误:ParentDataWidget 的使用不正确。此错误的原因是Positioned小部件,但我不确定为什么......
return Scaffold(
body: Container(
color: Colors.red,
child: Positioned(
left: 32.0,
child: Container(
width: 128.0,
height: 128.0,
color: Colors.yellow,
),
),
),
);
Run Code Online (Sandbox Code Playgroud) 创建了一个新的 Firebase 项目。创建了一个测试函数,如此处所述。
尝试调用此函数时,无论是尝试从我的 flutter 应用程序调用它还是直接调用它(403 Forbidden),我都会收到 PERMISSION DENIED 的消息(403 Forbidden)。
这篇文章的建议没有帮助......
这是我的第二个 flutter-firebase 项目。第一个运行得很好,看不出它们之间有任何差异可以解释这种行为。感谢对此问题的任何帮助:)
我的代码:
const functions = require('firebase-functions');
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
Run Code Online (Sandbox Code Playgroud) 我创建了一个CupertinoDatePicker小部件,初始值设置为一个变量。
当用户单击屏幕中的另一个小部件时,我想将选择器中的选定值更新为该变量值 - 但它不起作用(尽管CupertinoDatePicker小部件被重建)。
这是一个错误还是我做错了什么?
代码(可以复制粘贴到 dartPad 中):
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
final _time = DateTime.now();
int _min = 5;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatefulWidget {
@override
createState() => MyWidgetSate();
}
class MyWidgetSate extends State<MyWidget> { …Run Code Online (Sandbox Code Playgroud) 一个现有的 Flutter 项目,之前多次构建和存档。
将 Xcode 升级到 14.3 后,在尝试存档项目时,出现以下错误:
命令 PhaseScriptExecution 失败,退出代码非零
尝试清理、更新 Pod 等。没有任何帮助......
有任何想法吗?
在 Flutter 中使用getX,假设我需要为不同的控制器使用相同的服务。
例如,UsersController 和 ProductsController 具有相同的数据库服务。
这样做的最佳实践是什么?