Getting Errors integrating Amplitude Flutter Package into Flutter

335 Views Asked by At

I used the following reference code from the Amplitude team: https://developers.amplitude.com/docs/flutter-setup

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");
0

There are 0 best solutions below