I am trying to connect Amplify Api to my project and keep getting an error that reads LateError (LateInitializationError: Field 'customTypeSchemas' has not been initialized.)
(Screenshot of the error is provided after the code snippet) which I take to mean that in the code that Amplify provided me there is a line somewhere that has late
prefix for customTypeSchemas
Field, which I can't find.
This is where I am initializing 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());
}
}
}
Here is my pubspec.yaml
dependencies
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
This is what's in the ModelProvider.dart
that Amplify downloaded.
/*
* 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);
}
}
}
}
I did accidentally installed amplify_core: ^0.3.2
, which I remove and ran flutter clean
and, in ios folder, pod cache clean --all
.
Steps to reproduce the problem:
- Create flutter project
- Add Amplify to your project
- Add Database plugin
- Add Api to your project
- Try adding api plugin and run the app in iOS Simulator.
I am relatively new to programming and StackOverflow, so please excuse any mistakes I may have made in this post. Let me know if you need more info or you want to try something out.
Thanks in advance.
_configureAmplify
is a future method, useFutureBuilder
. You can also make it nullable and do a null check while using the model.You can check When should I use a FutureBuilder?
Example code: check above link.