App for Chat GPT, This project build with flutter and Dall-E 2 will be added.
Packages used in this project
- provider
- json_serializable
- hive
- dotenv
- dio
- animated_text_kit for Typing effect
You have to create .env
file into base of your project and give your OpenAI API Key as BEARER = 'API_KEY'
OR
Go to file lib/config/constants/api_constants.dart then
Change this
import 'package:flutter_dotenv/flutter_dotenv.dart' show dotenv; // Remove this line
class APIConstants {
//..
static String authToken = 'Bearer ${dotenv.env['BEARER_TOKEN']}'
//..
}
to this
class APIConstants {
//..
static String authToken = 'Bearer API_KEY'
//..
}
I used hive for save chat history. I firstly tried save history of messages as List<Message?>
but because of limitation of Dart it was not possible to save generic list to Hive
so i created a Class named HiveChatModel and saved it as is.
class HiveChatModel{
String? title;
DateTime? date;
List<Message?>? chat;
}
Ability to load history messages and continue to chat then saved it again i used Hive.put()
Hive.put(sesionName,messages)
when you load a chat, you also get sessionName
sessionName
is generated as session_${lengthOfHiveHistoryList}

