我刚刚开始学习 AWS Amplify 并按照https://aws.amazon.com/getting-started/hands-on/build-flutter-app-amplify/module-two/中给出的步骤在我的颤振中初始化 Amplify项目。但是当我尝试在我的应用程序中集成 Amplify(使用语句final _amplify = Amplify(); )时,我得到了The method 'Amplify' is not defined for type '_MyAppState'错误。
下面是我的 main.dart 文件。
import 'package:flutter/material.dart';
import './amplifyconfiguration.dart';
import 'package:amplify_core/amplify_core.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _amplify = Amplify();
@override
void initState() {
super.initState();
_configureAmplify();
}
@override
Widget build(BuildContext context) {
return Container();
}
void _configureAmplify() async {
try {
await _amplify.configure(amplifyconfig);
print('Successfully configured Amplify ');
} catch (e) {
print('Could not configure Amplify ☠️');
}
}
}
放大我在 pubspec.yaml 中导入的依赖项
amplify_core: '<1.0.0'
放大配置.dart
const amplifyconfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0"
}''';
此外,当我运行“Amplify 控制台”时,我得到的App 的 ID 为:未找到 xxxxxxxxxx