I posted here: https://stackoverflow.com/questions/72298875/getting-errors-integrating-amplitude-flutter-package-into-flutter
Here is what I posted:
I used the following reference code from the Amplitude team: [https://developers.amplitude.com/docs/flutter-setup][1]
Here is the relevant portion of my code:
import 'package:flutter/material.dart';<br /> import 'package:amplitude_flutter/amplitude.dart';<br /> import 'package:amplitude_flutter/identify.dart';<br /><br /> void main() {<br /> runApp(const MyApp());<br /> }<br /><br /> class MyApp extends StatelessWidget {<br /> const MyApp({Key? key}) : super(key: key);<br /><br /> // Create the instance<br /> final Amplitude analytics = Amplitude.getInstance(instanceName: "Assembly");<br /><br /> // Initialize SDK<br /> analytics.init(a46xxxxxxxxxxxxxxxx87e); <br /><br /> // Log an event<br /> analytics.logEvent('MyApp startup', eventProperties: {<br /> 'friend_num': 10,<br /> 'is_heavy_user': true<br /> });
HOWEVER, when running on my local Mac, I get the following errors:
lib/main.dart:16:5: Error: The name of a constructor must match the name of the enclosing class.<br /> analytics.init(a46xxxxxxxxxxxxxxxx87e); <br /> ^^^^^^^^^<br /> lib/main.dart:19:24: Error: Expected an identifier, but got ''Assembly''.<br /> Try inserting an identifier before ''Assembly''.<br /> analytics.logEvent('Assembly', eventProperties: {<br /> ^^^^^^^^^^<br /> lib/main.dart:19:51: Error: Non-optional parameters can't have a default value.<br /> Try removing the default value or making the parameter optional.<br /> analytics.logEvent('Assembly', eventProperties: {<br /> ^<br /> lib/main.dart:19:5: Error: The name of a constructor must match the name of the enclosing class.<br /> analytics.logEvent('Assembly', eventProperties: {<br /> ^^^^^^^^^<br /> lib/main.dart:13:43: Error: Method invocation is not a constant expression.<br /> final Amplitude analytics = Amplitude.getInstance(instanceName: "Assembly");
There were a few inconsistencies in the documentation.
- Under initialize, it sets it up
Amplitude.getInstance().init(a4638276fed4b8ea5c5a9ed13f07987e);
-
But then it says to initialize the following way within the sample code:
// Create the instance<br /> final Amplitude analytics = Amplitude.getInstance(instanceName: "project");<br /><br />// Initialize SDK<br /> analytics.init(widget.apiKey);
It’s unclear to me which is the way to reference the instance (among other things) based on the code example.
-
-
[1]: https://developers.amplitude.com/docs/flutter-setup