@@ -3,10 +3,10 @@ In this tutorial, you will integrate basic functionality for **Analytics**.
3
3
First, delete the contents of your app's * main.dart* file and paste in this starter boilerplate UI code.
4
4
5
5
``` dart
6
- import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
7
6
import 'package:flutter/material.dart';
8
- import 'package:amplify_core/amplify_core .dart';
7
+ import 'package:amplify_flutter/amplify .dart';
9
8
import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
9
+ import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
10
10
import 'amplifyconfiguration.dart';
11
11
12
12
void main() {
@@ -21,9 +21,6 @@ class MyApp extends StatefulWidget {
21
21
class _MyAppState extends State<MyApp> {
22
22
bool _amplifyConfigured = false;
23
23
24
- // Instantiate Amplify
25
- Amplify amplifyInstance = Amplify();
26
-
27
24
@override
28
25
void initState() {
29
26
super.initState();
@@ -51,7 +48,7 @@ class _MyAppState extends State<MyApp> {
51
48
Text(
52
49
_amplifyConfigured ? "configured" : "not configured"
53
50
),
54
- RaisedButton (
51
+ ElevatedButton (
55
52
onPressed: _amplifyConfigured ? _recordEvent : null,
56
53
child: const Text('record event')
57
54
)
@@ -76,13 +73,11 @@ void _configureAmplify() async {
76
73
if (!mounted) return;
77
74
78
75
// 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());
83
78
84
79
// Once Plugins are added, configure Amplify
85
- await amplifyInstance .configure(amplifyconfig);
80
+ await Amplify .configure(amplifyconfig);
86
81
try {
87
82
setState(() {
88
83
_amplifyConfigured = true;
@@ -94,9 +89,9 @@ void _configureAmplify() async {
94
89
}
95
90
```
96
91
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.
98
93
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 .
100
95
101
96
## Recording a simple event with Analytics
102
97
@@ -114,4 +109,4 @@ void _recordEvent() async {
114
109
}
115
110
```
116
111
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.
0 commit comments