ChatController class

Drives a chat transcript. Plain ChangeNotifier, so it works with Riverpod, Bloc, Provider or a bare AnimatedBuilder — no state management imposed.

Note on exceptions: the model and webSearch setters throw a plain StateError (from dart:core), not a ChatGptException, when called while isStreaming is true — see model's doc comment. A blanket on ChatGptException catch (e) { ... } around UI code that also calls these setters will not catch that; guard the setter call itself instead (e.g. disable the control while isStreaming is true).

Inheritance

Constructors

ChatController({ChatGptClient? client, String systemPrompt = '', String model = 'auto', bool? webSearch, void onLog(String line)?})
Creates a controller.

Properties

currentOptions → SendOptions
The SendOptions a call to send that omits its own options argument would build for the next turn: SendOptions(model: model, webSearch: webSearch), read fresh from this controller's current model and webSearch every time this getter is read (not cached), so it reflects a setter call made moments — or a frame — earlier.
no setter
downgradeNotice → String?
Set when the backend answered with a different model than requested.
no setter
error → ChatGptException?
The last error, if any.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
isStreaming → bool
True while a reply is streaming.
no setter
isWritingReply → bool
True only while the assistant is actually writing.
no setter
messages → List<ChatMessage>
The transcript.
no setter
model ↔ String
Model requested for a turn that does not pass its own SendOptions to send — see send's doc comment for the exact precedence rule.
getter/setter pair
onLog → void Function(String line)?
Optional timeline of a turn, for diagnosing why a UI still looks busy.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
title → String?
The title the backend generated for this conversation, if any.
no setter
webSearch ↔ bool?
Force web search on or off for a turn that does not pass its own SendOptions to send; null lets the model decide. See model for the mutability, conversation-continuity and streaming-guard notes — they apply identically here.
getter/setter pair

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
clear() → Future<void>
Starts a fresh conversation.
dispose() → void
Discards any resources used by the object.
override
limits() → Future<Limits>
Reads the anonymous quota for THIS session's device.
loadHistory() → Future<String?>
Re-fetches this conversation from the backend, replacing the transcript.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
retry() → Future<void>
Resends the prompt from the last send call that failed.
send(String text, {SendOptions? options, List<TextAttachment> attachments = const []}) → Future<void>
Sends text and streams the reply into messages.
stop() → void
Cancels the turn in flight.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited