Skip to content

Update flutter getting started code samples as per refactor #2881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions docs/start/getting-started/fragments/flutter/integrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ In this tutorial, you will integrate basic functionality for **Analytics**.
First, delete the contents of your app's *main.dart* file and paste in this starter boilerplate UI code.

```dart
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:flutter/material.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_flutter/amplify.dart';
import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'amplifyconfiguration.dart';

void main() {
Expand All @@ -21,9 +21,6 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
bool _amplifyConfigured = false;

// Instantiate Amplify
Amplify amplifyInstance = Amplify();

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -51,7 +48,7 @@ class _MyAppState extends State<MyApp> {
Text(
_amplifyConfigured ? "configured" : "not configured"
),
RaisedButton(
ElevatedButton(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch.

onPressed: _amplifyConfigured ? _recordEvent : null,
child: const Text('record event')
)
Expand All @@ -76,13 +73,11 @@ void _configureAmplify() async {
if (!mounted) return;

// Add Pinpoint and Cognito Plugins
AmplifyAnalyticsPinpoint analyticsPlugin = AmplifyAnalyticsPinpoint();
AmplifyAuthCognito authPlugin = AmplifyAuthCognito();
amplifyInstance.addPlugin(authPlugins: [authPlugin]);
amplifyInstance.addPlugin(analyticsPlugins: [analyticsPlugin]);
Amplify.addPlugin(AmplifyAnalyticsPinpoint());
Amplify.addPlugin(AmplifyAuthCognito());

// Once Plugins are added, configure Amplify
await amplifyInstance.configure(amplifyconfig);
await Amplify.configure(amplifyconfig);
try {
setState(() {
_amplifyConfigured = true;
Expand All @@ -94,9 +89,9 @@ void _configureAmplify() async {
}
```

Note that all calls to `addPlugin` are made before `amplify.configure` is called.
Note that all calls to `addPlugin()` are made before `Amplify.configure()` is called.

`amplify.configure` should only be called once. Calling it multiple times will result in an error.
`Amplify.configure()` should only be called once. Calling it multiple times will result in an exception.

## Recording a simple event with Analytics

Expand All @@ -114,4 +109,4 @@ void _recordEvent() async {
}
```

At this point you are almost ready to run your app. In the next section, we will use Amplify CLI to configure your backend AWS resources.
At this point you are almost ready to run your app. In the next section, we will use Amplify CLI to configure your backend AWS resources.
2 changes: 1 addition & 1 deletion docs/start/getting-started/fragments/flutter/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies:
flutter:
sdk: flutter

amplify_core: '<1.0.0'
amplify_flutter: '<1.0.0'
amplify_auth_cognito: '<1.0.0'
amplify_analytics_pinpoint: '<1.0.0'
```
Expand Down