Skip to content

Commit 2a46c44

Browse files
authored
Merge pull request #2881 from aws-amplify/core_refactor
Update flutter getting started code samples as per refactor
2 parents 3851916 + 5751f6a commit 2a46c44

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

docs/start/getting-started/fragments/flutter/integrate.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ In this tutorial, you will integrate basic functionality for **Analytics**.
33
First, delete the contents of your app's *main.dart* file and paste in this starter boilerplate UI code.
44

55
```dart
6-
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
76
import 'package:flutter/material.dart';
8-
import 'package:amplify_core/amplify_core.dart';
7+
import 'package:amplify_flutter/amplify.dart';
98
import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
9+
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
1010
import 'amplifyconfiguration.dart';
1111
1212
void main() {
@@ -21,9 +21,6 @@ class MyApp extends StatefulWidget {
2121
class _MyAppState extends State<MyApp> {
2222
bool _amplifyConfigured = false;
2323
24-
// Instantiate Amplify
25-
Amplify amplifyInstance = Amplify();
26-
2724
@override
2825
void initState() {
2926
super.initState();
@@ -51,7 +48,7 @@ class _MyAppState extends State<MyApp> {
5148
Text(
5249
_amplifyConfigured ? "configured" : "not configured"
5350
),
54-
RaisedButton(
51+
ElevatedButton(
5552
onPressed: _amplifyConfigured ? _recordEvent : null,
5653
child: const Text('record event')
5754
)
@@ -76,13 +73,11 @@ void _configureAmplify() async {
7673
if (!mounted) return;
7774
7875
// Add Pinpoint and Cognito Plugins
79-
AmplifyAnalyticsPinpoint analyticsPlugin = AmplifyAnalyticsPinpoint();
80-
AmplifyAuthCognito authPlugin = AmplifyAuthCognito();
81-
amplifyInstance.addPlugin(authPlugins: [authPlugin]);
82-
amplifyInstance.addPlugin(analyticsPlugins: [analyticsPlugin]);
76+
Amplify.addPlugin(AmplifyAnalyticsPinpoint());
77+
Amplify.addPlugin(AmplifyAuthCognito());
8378
8479
// Once Plugins are added, configure Amplify
85-
await amplifyInstance.configure(amplifyconfig);
80+
await Amplify.configure(amplifyconfig);
8681
try {
8782
setState(() {
8883
_amplifyConfigured = true;
@@ -94,9 +89,9 @@ void _configureAmplify() async {
9489
}
9590
```
9691

97-
Note that all calls to `addPlugin` are made before `amplify.configure` is called.
92+
Note that all calls to `addPlugin()` are made before `Amplify.configure()` is called.
9893

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

10196
## Recording a simple event with Analytics
10297

@@ -114,4 +109,4 @@ void _recordEvent() async {
114109
}
115110
```
116111

117-
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.
112+
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.

docs/start/getting-started/fragments/flutter/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ dependencies:
7474
flutter:
7575
sdk: flutter
7676
77-
amplify_core: '<1.0.0'
77+
amplify_flutter: '<1.0.0'
7878
amplify_auth_cognito: '<1.0.0'
7979
amplify_analytics_pinpoint: '<1.0.0'
8080
```

0 commit comments

Comments
 (0)