I've just started learning AWS Amplify and followed the step given in https://aws.amazon.com/getting-started/hands-on/build-flutter-app-amplify/module-two/ to initialize Amplify in my flutter project. But I'm getting The method 'Amplify' isn't defined for the type '_MyAppState' error when I'm trying to integrate Amplify (with statement final _amplify = Amplify();) in my App.
Below is my main.dart file.
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 ☠️');
}
}
}
Amplify dependency that I have imported in pubspec.yaml
amplify_core: '<1.0.0'
amplifyconfiguration.dart
const amplifyconfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0"
}''';
Also when I run "Amplify console", I'm getting App with id: xxxxxxxxxx not found
According to https://github.com/aws-amplify/amplify-flutter/issues/274 amplify_core is now renamed to amplify_flutter so you need to change
to
In addition, as Amplify class is a static singleton now, you don't need to instantiate it, so you can remove this line: