skip to Main Content

I’ve encountered a problem while using the Dart programming language in a Flutter project. Specifically, I’m trying to import a package called ‘chat_gpt_sdk’ into my Dart code. In my code, I have the following import statement:

However, when I attempt to use a class named ‘ChatGPT’ that is supposed to be included in this package, I receive an error message stating "Undefined class ‘ChatGPT’."

I’ve reviewed the package’s documentation and explored its source code, and it does indeed contain a class named ‘ChatGPT.’ Additionally, I’ve considered potential version compatibility problems, but the package version I’m using should include the ‘ChatGPT’ class.

This issue is impeding my project’s progress, and I’m seeking guidance on how to resolve it. If anyone has encountered a similar problem or can provide insights into what might be causing this error, I’d greatly appreciate your assistance. Thank you in advance for your help!

`

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart';
import 'package:chat_gpt_sdk/chat_gpt_sdk.dart';

import "chatmessage.dart";
import 'colors.dart' as color;

class ChatScreen extends StatefulWidget {
  const ChatScreen({super.key});

  @override
  State<ChatScreen> createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
  final TextEditingController _controller = TextEditingController();
  final List<Chatmessage> _messages = [];
  ChatGPT? chatGPT;

  StreamSubscription? _subscription;

  
 
  void _SendMessage() {
    Chatmessage _message = Chatmessage(text: _controller.text, sender: "user");
    setState(() {
      _messages.insert(0, _message);
    });
    _controller.clear();

  }

  Widget _buildTextComposer() {
    return Row(
      children: [
        Expanded(
          child: TextField(
            controller: _controller,
            onSubmitted: (value) => _SendMessage(),
            decoration: InputDecoration.collapsed(hintText: "Send a mesaage"),
          ),
        ),
        IconButton(
            onPressed: () => _SendMessage(), icon: const Icon(Icons.send))
      ],
    ).px16();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: color.AppColor.homePageBackground,
        body: SafeArea(
            child: Center(
          child: Column(children: [
            Text("What going on with you"),
            Flexible(
                child: ListView.builder(
              reverse: true,
              padding: Vx.m8,
              itemCount: _messages.length,
              itemBuilder: (context, index) {
                return _messages[index];
              },
            )),
            Container(
              decoration: BoxDecoration(
                color: context.cardColor,
              ),
              child: _buildTextComposer(),
            )
          ]),
        )));
  }
}
`

Pubspecyaml file

name: chat_gpt_02
description: A new Flutter project.


environment:
  sdk: ">=2.18.6 <3.0.0"

  chat_gpt_sdk:
    git:
      url: https://github.com/iampawan/Flutter-ChatGPT.git
  cupertino_icons: ^1.0.2
  flutter:
    sdk: flutter
  flutter_dotenv: ^5.0.2
  velocity_x: ^3.6.0

dev_dependencies:
 
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter

assets section, like this:
  
  assets:
    - imageslogo.png  #   - images/a_dot_burr.jpeg

2

Answers


  1. You can add the package by following the installation instructions provided in the Git repository as follows:

    chat_gpt: 2.0.4
    
    Login or Signup to reply.
  2. The latest version of the chat_gpt_sdk package that supports ChatGPT class is 1.0.2+3. Starting from version 1.0.2+4, you should use OpenAI class instead.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search