Skip to content

Undefined method 'AccessToken' and 'VideoGrant' in Flutter project #905

@famplusmobile-bot

Description

@famplusmobile-bot

Describe the bug
I am trying to use livekit_client in a new Flutter project, but I am getting "Undefined method 'AccessToken'" and "Undefined method 'VideoGrant'" errors. I have followed all the setup steps.

To Reproduce

  1. Create a new Flutter project.
  2. Add livekit_client: any to pubspec.yaml.
  3. Run flutter pub get.
  4. Use the following code in main.dart.

Code sample

import 'package:flutter/material.dart';
import 'package:livekit_client/livekit_client.dart';

// My Keys
const String LIVEKIT_URL = 'wss://...'; // Replaced with my actual URL
const String LIVEKIT_API_KEY = 'API...'; // Replaced with my actual Key
const String LIVEKIT_API_SECRET = '...'; // Replaced with my actual Secret

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) => const MaterialApp(home: HomePage());
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  String createAccessToken() {
    final token = AccessToken(
      LIVEKIT_API_KEY,
      LIVEKIT_API_SECRET,
      identity: 'test-user',
      name: 'Test User',
    );
    token.setGrant(VideoGrant(
      room: 'test-room',
      roomJoin: true,
    ));
    return token.toJwt();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            try {
              createAccessToken();
              print('Success!');
            } catch (e) {
              print('Error: $e');
            }
          },
          child: const Text('Test Token'),
        ),
      ),
    );
  }
}


   Expected behavior
The code should compile without errors, and AccessToken and VideoGrant should be recognized.
Platform information
OS: Windows
Flutter version:
[ Flutter 3.35.7 • channel stable • https://github.com/flutter/flutter.git
Framework • revision adc9010625 (7 days ago) • 2025-10-21 14:16:03 -0400
Engine • hash 6b24e1b529bc46df7ff397667502719a2a8b6b72 (revision 035316565a) (7 days ago) • 2025-10-2114:28:01.000Z ]
ToolsDart 3.9.2DevTools 2.48.0
livekit_client version: 2.5.3
Additional context
I have already tried flutter clean, flutter pub cache repair, and restarting the IDE. The errors persist. It seems like the necessary classes are not being exported correctly from the library. Am I missing a specific import?

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