我正在尝试将 Amplify Api 连接到我的项目并不断收到错误消息LateError (LateInitializationError: Field 'customTypeSchemas' has not been initialized.)
(在代码片段之后提供了错误的屏幕截图),我认为这意味着在 Amplify 提供给我的代码中,某处有一行带有late
前缀对于customTypeSchemas
字段,我找不到。
这是我初始化 Amplify 的地方。
@override
void initState() {
super.initState();
_configureAmplify();
}
void _configureAmplify() async {
if (!Amplify.isConfigured) {
await Amplify.addPlugins([
AmplifyDataStore(modelProvider: ModelProvider.instance),
AmplifyAPI(),
]);
try {
await Amplify.configure(amplifyconfig);
} catch (e) {
print(e.toString());
}
}
}
这是我的pubspec.yaml
依赖项
dependencies:
amplify_api: ^0.3.2
amplify_datastore: ^0.3.2
amplify_flutter: ^0.3.2
bloc: ^8.0.2
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
flutter_bloc: ^8.0.1
这是ModelProvider.dart
Amplify 下载的内容。
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
// ignore_for_file: public_member_api_docs
import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart';
import 'Todo.dart';
export 'Todo.dart';
class ModelProvider extends ModelProviderInterface {
@override
String version = "d960b875068d46ff04d68879d96cc042";
@override
List<ModelSchema> modelSchemas = [Todo.schema];
static final ModelProvider _instance = ModelProvider();
static ModelProvider get instance => _instance;
@override
ModelType getModelTypeByModelName(String modelName) {
switch (modelName) {
case "Todo":
{
return Todo.classType;
}
default:
{
throw Exception("Failed to find model in model provider for model name: " + modelName);
}
}
}
}
我确实不小心安装了amplify_core: ^0.3.2
,我删除并运行了它,flutter clean
并且在 ios 文件夹中pod cache clean --all
,
重现问题的步骤:
- 创建颤振项目
- 将 Amplify 添加到您的项目中
- 添加数据库插件
- 将 API 添加到您的项目中
- 尝试添加 api 插件并在 iOS 模拟器中运行该应用程序。
我对编程和 StackOverflow 比较陌生,所以请原谅我在这篇文章中可能犯的任何错误。如果您需要更多信息或想尝试一下,请告诉我。
提前致谢。