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';
import 'package:amplitude_flutter/amplitude.dart';
import 'package:amplitude_flutter/identify.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// Create the instance
final Amplitude analytics = Amplitude.getInstance(instanceName: "Assembly");
// Initialize SDK
analytics.init(a46xxxxxxxxxxxxxxxx87e);
// Log an event
analytics.logEvent('MyApp startup', eventProperties: {
'friend_num': 10,
'is_heavy_user': true
});
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.
analytics.init(a46xxxxxxxxxxxxxxxx87e);
^^^^^^^^^
lib/main.dart:19:24: Error: Expected an identifier, but got ''Assembly''.
Try inserting an identifier before ''Assembly''.
analytics.logEvent('Assembly', eventProperties: {
^^^^^^^^^^
lib/main.dart:19:51: Error: Non-optional parameters can't have a default value.
Try removing the default value or making the parameter optional.
analytics.logEvent('Assembly', eventProperties: {
^
lib/main.dart:19:5: Error: The name of a constructor must match the name of the enclosing class.
analytics.logEvent('Assembly', eventProperties: {
^^^^^^^^^
lib/main.dart:13:43: Error: Method invocation is not a constant expression.
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
final Amplitude analytics = Amplitude.getInstance(instanceName: "project");
// Initialize SDK
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