fixed bugs relating to ui and duplicating conversations.

This commit is contained in:
Joshua
2024-07-09 17:36:21 -06:00
parent 78e7f4b896
commit 097b99e0e6
15 changed files with 352 additions and 62 deletions
@@ -8,10 +8,13 @@ class ChatBubbleWidget extends StatelessWidget{
@override
Widget build(BuildContext context) {
double max_width = MediaQuery.of(context).size.width*0.65;
return Row(
mainAxisAlignment: c.role ? MainAxisAlignment.end : MainAxisAlignment.start,
children: [
Container(
width: max_width,
padding: const EdgeInsets.all(16.0),
margin: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
@@ -14,11 +14,9 @@ import 'package:cached_network_image/cached_network_image.dart';
class ConversationThreadModel extends FlutterFlowModel<ConversationThreadWidget> {
final formKey = GlobalKey<FormState>();
late PromptBoxModel promptBoxModel;
late Conversation conversation;
Conversation conversation;
void updateConversation() {
conversation = Server.getLoadedConversation();
}
ConversationThreadModel(this.conversation);
@override
void initState(BuildContext context) {
@@ -15,15 +15,19 @@ import 'conversation_thread_model.dart';
export 'conversation_thread_model.dart';
class ConversationThreadWidget extends StatefulWidget {
const ConversationThreadWidget({super.key});
final Conversation conversation;
const ConversationThreadWidget({super.key, required this.conversation});
@override
State<ConversationThreadWidget> createState() =>
_ConversationThreadWidgetState();
_ConversationThreadWidgetState(conversation);
}
class _ConversationThreadWidgetState extends State<ConversationThreadWidget> {
late ConversationThreadModel _model;
Conversation conversation;
_ConversationThreadWidgetState(this.conversation);
@override
void setState(VoidCallback callback) {
@@ -34,7 +38,7 @@ class _ConversationThreadWidgetState extends State<ConversationThreadWidget> {
@override
void initState() {
super.initState();
_model = createModel(context, () => ConversationThreadModel());
_model = createModel(context, () => ConversationThreadModel(conversation));
}
@override
@@ -66,11 +70,7 @@ class _ConversationThreadWidgetState extends State<ConversationThreadWidget> {
reverse: false,
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
if(Server.getLoadedConversation().chats.last.role) {
return ChatBubbleWidget(c: Server.getLoadedConversation().chats[index]);
} else {
}
return ChatBubbleWidget(c: Server.getLoadedConversation().chats[index]);
},
);
},
@@ -221,6 +221,7 @@ class _PromptBoxWidgetState extends State<PromptBoxWidget> {
onFieldSubmitted: (text) {
// TODO: Clear text box
Server.respondWhenReady(text); // TODO: Connect with multimedia
_model.textController?.clear(); // Clear the text field
},
),
),
+1 -5
View File
@@ -31,10 +31,6 @@ BottomNavigationBarItem _buildNavigationItem(int index) {
label = 'Home';
iconData = Icons.home;
break;
case 2:
label = 'Chat';
iconData = Icons.bubble_chart;
break;
}
return BottomNavigationBarItem(
icon: Icon(iconData),
@@ -56,7 +52,7 @@ class MyApp extends ConsumerWidget {
final selectedIndexProvider = StateProvider<int>((_) => 1); // Initial state
// This list holds the pages to navigate between
final List<Widget> _pages = [
static final List<Widget> _pages = [
const Center(child: SettingsWidget()),
const Center(child: ConversationsListWidget()),
];
+7 -1
View File
@@ -1,3 +1,5 @@
import 'package:app/components/conversation_thread/conversation.dart';
import '/components/conversation_thread/conversation_thread_widget.dart';
import '/components/model_item/model_item_widget.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
@@ -13,9 +15,13 @@ class ConversationModel extends FlutterFlowModel<ConversationWidget> {
// Model for ModelItem component.
late ModelItemModel modelItemModel;
late Conversation conversation;
ConversationModel(this.conversation);
@override
void initState(BuildContext context) {
conversationThreadModel = createModel(context, () => ConversationThreadModel()); // TODO
conversationThreadModel = createModel(context, () => ConversationThreadModel(conversation)); // TODO
modelItemModel = createModel(context, () => ModelItemModel());
}
@@ -1,3 +1,5 @@
import 'package:app/components/conversation_thread/conversation.dart';
import '/components/conversation_details_overlay/conversation_details_overlay_widget.dart';
import '/components/conversation_thread/conversation_thread_widget.dart';
import '/components/model_item/model_item_widget.dart';
@@ -10,22 +12,24 @@ import 'conversation_model.dart';
export 'conversation_model.dart';
class ConversationWidget extends StatefulWidget {
const ConversationWidget({super.key});
final Conversation conversation;
const ConversationWidget({super.key, required this.conversation});
@override
State<ConversationWidget> createState() => _ConversationWidgetState();
State<ConversationWidget> createState() => _ConversationWidgetState(conversation);
}
class _ConversationWidgetState extends State<ConversationWidget> {
late ConversationModel _model;
Conversation conversation;
_ConversationWidgetState();
_ConversationWidgetState(this.conversation);
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
void initState() {
super.initState();
_model = createModel(context, () => ConversationModel());
_model = createModel(context, () => ConversationModel(conversation));
}
@override
@@ -124,7 +128,7 @@ class _ConversationWidgetState extends State<ConversationWidget> {
child: wrapWithModel(
model: _model.conversationThreadModel,
updateCallback: () => setState(() {}),
child: const ConversationThreadWidget(),
child: ConversationThreadWidget(conversation: conversation),
),
),
),
@@ -2,7 +2,6 @@ import 'package:app/components/conversation_thread/conversation.dart';
import 'package:app/theme.dart';
import 'package:app/pages/conversation_widget.dart';
import 'package:app/components/conversation_options/conversation_options_widget.dart';
import 'package:app/util/server.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
@@ -22,14 +21,8 @@ class ConversationsListWidget extends StatefulWidget {
class _ConversationsListWidgetState extends State<ConversationsListWidget> {
late ConversationsListModel _model;
final selectedIndexProvider = StateProvider<int>((_) => 0); // Initial state
late List<Widget> conversations = [];
// = [
// // TODO: Dynamically generate list of pages based upon existing conversations.
// // This requires retrievable conversations from the server side.
// const Center(child: ConversationWidget()),
// ];
static List<ConversationWidget> conversations = [];
final scaffoldKey = GlobalKey<ScaffoldState>();
@@ -37,9 +30,12 @@ class _ConversationsListWidgetState extends State<ConversationsListWidget> {
void initState() {
super.initState();
Server().init();
List<Conversation> convos = Server.conversations;
for(Conversation c in convos) {
conversations.add(const ConversationWidget());
if(conversations.isEmpty) {
List<Conversation> convoys = Server.conversations;
for(Conversation c in convoys) {
conversations.add(ConversationWidget(conversation: c,));
}
}
_model = createModel(context, () => ConversationsListModel());
@@ -53,7 +49,6 @@ class _ConversationsListWidgetState extends State<ConversationsListWidget> {
@override
Widget build(BuildContext context) {
List<Conversation> conversations = Server.getConversationsList();
return GestureDetector(
onTap: () => _model.unfocusNode.canRequestFocus
? FocusScope.of(context).requestFocus(_model.unfocusNode)
@@ -133,7 +128,7 @@ class _ConversationsListWidgetState extends State<ConversationsListWidget> {
mainAxisSize: MainAxisSize.max,
children: [
Text(
conversations[index].conversationLabel,
conversations[index].conversation.conversationLabel,
style: AppTheme.headlineLarge,
),
],
@@ -147,7 +142,7 @@ class _ConversationsListWidgetState extends State<ConversationsListWidget> {
children: [
Expanded(
child: Text(
conversations[index].conversationSubLabel,
conversations[index].conversation.conversationSubLabel,
style: AppTheme.bodyMedium,
),
),
@@ -181,7 +176,7 @@ class _ConversationsListWidgetState extends State<ConversationsListWidget> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ConversationWidget(),
builder: (context) => ConversationWidget(conversation: Server.getLoadedConversation(),),
),
)
},
+17 -16
View File
@@ -12,7 +12,8 @@ class Server {
static final Server _single_server = Server._internal();
Server._internal();
// TODO: One-time process to establish server connection is required for easy setup/maintenance.
static final url = "http://10.0.2.2:11434/api/";
static final url = "http://10.0.2.2:11434/api/"; // For emulated device in testing
//static final url = "http://192.168.1.68:11434/api"; // For local access to home server
static String endpoint = "";
static final Map<String, String> headers = {'Content-Type': 'application/json'};
@@ -55,26 +56,26 @@ class Server {
conversations.add(
Conversation.completeConversation(
0,
"Test label",
"Test sub-label",
"Test Conversation",
"Testing Functionality",
[
(Chat("This is just a test. Only reply Yes.", true)),
(Chat("Yes.", false)),
(Chat("Hello there! You are part of a prototype and are running locally on my Macbook Air. Please keep your responses brief as every prompt freezes my computer.", true)),
(Chat("Understood! How can I help?", false)),
]
)
);
conversations.add(
Conversation.completeConversation(
1,
"Label test",
"Sub-label Test",
[
(Chat("A different test. Only reply No.", true)),
(Chat("No.", false)),
]
)
);
// conversations.add(
// Conversation.completeConversation(
// 1,
// "Label test",
// "Sub-label Test",
// [
// (Chat("A different test. Only reply No.", true)),
// (Chat("No.", false)),
// ]
// )
// );
}