LoginSignup
1
1

More than 1 year has passed since last update.

Amplifyクラスのコンストラクタが見つからない

Posted at

現象

以下のページを参照しつつ、Flutter + AWS Amplifyの環境を構築していたら、
手順書通りにやっているのに、Amplifyのコンストラクタが見つからないって言われる。

  • 実際のコード
main.dart
  // こいつがエラーになる
  final _amplify = Amplify();
  final _authService = AuthService();
  • エラー内容

The method 'Amplify' isn't defined for the type '_MyAppState'.
Try correcting the name to the name of an existing method, or defining a method named 'Amplify'.

解決

以下の二点が手順書間違い。

  1. Amplifyのライブラリ[amplify_core]を[amplify_flutter]に変更する。
  2. pubspec.yaml
    # amplify_core: '<1.0.0'
    amplify_flutter: '<1.0.0'
    
  3. Amplifyは静的クラスとなっているので、インスタンス作らなくて良い。

main.dart
  // 削除
  // final _amplify = Amplify();
  final _authService = AuthService();


  ~~


  // 変更
  // await _amplify.configure(amplifyconfig);
  await Amplify.configure(amplifyconfig);

これでビルドエラーは消えました!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1