我刚刚开始学习 AWS Amplify,并按照 https://aws.amazon.com/getting-started/hands-on/build-flutter-app-amplify/module-two/ 中给出的步骤在我的 flutter 项目中初始化 Amplify。但是,当我尝试集成 Amplify(使用语句 final _amplify = Amplify();< /strong>) 在我的应用中。
下面是我的 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'
amplifyconfiguration.dart
const amplifyconfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0"
}''';
此外,当我运行“Amplify 控制台”时,我得到 ID 为:xxxxxxxxxx 未找到的应用
答案 0 :(得分:1)
根据https://github.com/aws-amplify/amplify-flutter/issues/274 amplify_core 现在重命名为 amplify_flutter 所以你需要改变
client.on("message"...
到
amplify_core: '<1.0.0'
另外,由于Amplify类现在是静态单例,不需要实例化,可以去掉这一行:
amplify_flutter: '<1.0.0'