Skip to content

Configuration is not defined when initializing createClient #182

@chownation

Description

@chownation

Goal

Enable Segment analytics tracking in our app integrated into Flutter module.

Problem

After adding the segment_analytics dependency (per https://github.com/segmentio/analytics_flutter/blob/main/example/lib/main.dart), consistently facing error:

1 error • The function 'Configuration' isn't defined • lib/main.dart:13:7 • undefined_function

Error occurs during the initialization of the analytics client:

   1 analytics = createClient(
   2       Configuration(writeKey: "YOUR_WRITE_KEY"));

Steps Taken

Attempts to resolve:

  1. Trying different versions of segment_analytics:

    • ^1.1.9
    • ^1.0.1
    • 1.1.7 (pinned)
  2. Trying different import combinations:

    • import 'package:segment_analytics/client.dart';
    • import 'package:segment_analytics/analytics.dart';
    • import 'package:segment_analytics/plugin.dart';
    • A combination of the above.
  3. Using fully qualified names:

    • Importing analytics.dart as segment_analytics and using segment_analytics.Configuration.

Current State

Relevant files are in the following state:

pubspec.yaml

   1 dependencies:
   2   flutter:
   3     sdk: flutter
   4
   5   segment_analytics: 1.1.7

lib/main.dart

    1 import 'package:flutter/material.dart';
    2 import 'package:segment_analytics/analytics.dart';
    3 import 'package:segment_analytics/client.dart';
    4
    5 late final Analytics analytics;
    6
    7 void main() {
    8   analytics = createClient(
    9       Configuration(writeKey: "SEGMENT_WRITE_KEY"));
   10   runApp(const MyApp());
   11 }
   12
   13 // ... rest of the file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions