1

我刚刚开始学习 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

4

1 回答 1

3

根据https://github.com/aws-amplify/amplify-flutter/issues/274 amplify_core 现在重命名为 amplify_flutter 所以你需要改变

amplify_core: '<1.0.0'

amplify_flutter: '<1.0.0'

另外,由于 Amplify 类现在是一个静态单例,你不需要实例化它,所以你可以去掉这行:

final _amplify = Amplify();
于 2021-02-27T19:09:49.337 回答