Skip to content

Configuration is not defined when initializing createClient #182

Closed

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

Activity

  1. chownation commented on Sep 21, 2025

    @chownation
    Author

    specify import 'package:segment_analytics/state.dart' in Installation / Usage

    Setting up the client
    The package exposes a method called createClient which we can use to create the Segment Analytics client. This central client manages all our tracking events. It is recommended you add this as a property on your main app's state class.

    > const writeKey = 'SEGMENT_API_KEY';
    > final analytics = createClient(Configuration(writeKey));
    

    You must pass at least the writeKey. Additional configuration options are listed below:

    [Content]: add to https://pub.dev/packages/segment_analytics#setting-up-the-client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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