Skip to content

Commit 2bcb185

Browse files
author
logan
committed
update chatgpt page
1 parent 24416cc commit 2bcb185

File tree

6 files changed

+248
-146
lines changed

6 files changed

+248
-146
lines changed

flareline_uikit/lib/widget/flareline_layout.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ abstract class FlarelineLayoutWidget extends StatelessWidget {
2525

2626
Color? get backgroundColor => null;
2727

28+
EdgeInsetsGeometry? get padding =>
29+
const EdgeInsets.symmetric(horizontal: 20, vertical: 16);
30+
2831
Widget? toolbarWidget(BuildContext context, bool showDrawer) {
2932
return null;
3033
}
@@ -107,7 +110,7 @@ abstract class FlarelineLayoutWidget extends StatelessWidget {
107110
width: double.maxFinite,
108111
height: double.maxFinite,
109112
alignment: isAlignCenter ? Alignment.center : null,
110-
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
113+
padding: padding,
111114
child: isContentScroll
112115
? SingleChildScrollView(child: contentWidget)
113116
: contentWidget,

lib/entity/message_entity.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MessageEntity {
1111
late int timestamp;
1212
late String belongUid;
1313
late String conversationId;
14+
late String fromMessageId;
1415

1516
MessageEntity();
1617

lib/entity/message_entity.g.dart

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pages/chatgpt/chatgpt_page.dart

Lines changed: 141 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class ChatGptPage extends LayoutWidget {
3939
// TODO: implement backgroundColor
4040
Color? get backgroundColor => const Color(0xFF2b2b35);
4141

42+
@override
43+
// TODO: implement padding
44+
EdgeInsetsGeometry? get padding => null;
45+
4246
@override
4347
Widget contentDesktopWidget(BuildContext context) {
4448
return ContentPage();
@@ -56,69 +60,75 @@ class ContentPage extends BaseStlessWidget<ChatGptProvider> {
5660
@override
5761
Widget bodyWidget(
5862
BuildContext context, ChatGptProvider viewModel, Widget? child) {
59-
return Column(
63+
return Row(
6064
children: [
65+
_buildLeftNavigation(context, viewModel),
6166
Expanded(
62-
child: Stack(
63-
alignment: Alignment.topCenter,
64-
children: [
65-
_gptMessageWidget(context, viewModel),
66-
Visibility(
67-
visible: viewModel.showConversation,
68-
child: ConversationPage(
69-
onVisibleChanged: (visible) {
70-
viewModel.showConversation = visible;
71-
},
72-
),
73-
),
74-
Align(
75-
child: _toolsWidget(context, viewModel),
76-
alignment: Alignment.centerLeft,
77-
),
78-
],
79-
),
80-
),
81-
const SizedBox(
82-
height: 20,
83-
),
84-
Container(
85-
margin: EdgeInsets.symmetric(horizontal: margin),
86-
alignment: Alignment.center,
87-
child: Column(children: [
88-
Visibility(
89-
visible: viewModel.showSettings,
90-
child: const Column(
67+
child: Column(
68+
children: [
69+
SizedBox(height: 10,),
70+
Expanded(
71+
child: Stack(
72+
alignment: Alignment.topCenter,
9173
children: [
92-
OpenAiSetting(),
93-
SizedBox(
94-
height: 20,
74+
_gptMessageWidget(context, viewModel),
75+
Visibility(
76+
visible: viewModel.showConversation,
77+
child: ConversationPage(
78+
onVisibleChanged: (visible) {
79+
viewModel.showConversation = visible;
80+
},
81+
),
9582
),
9683
],
9784
),
9885
),
99-
OutBorderTextFormField(
100-
hintText: 'Message ChatGPT...',
101-
controller: viewModel.controller,
102-
textInputAction: TextInputAction.send,
103-
textStyle: const TextStyle(color: Colors.white),
104-
focusColor: GlobalColors.success,
105-
onFieldSubmitted: (value) {
106-
viewModel.send(context);
107-
},
108-
suffixWidget: InkWell(
109-
child: Icon(
110-
Icons.send,
111-
color: viewModel.isLoading
112-
? GlobalColors.border
113-
: GlobalColors.success,
86+
const SizedBox(
87+
height: 20,
88+
),
89+
Container(
90+
margin: EdgeInsets.symmetric(horizontal: margin),
91+
alignment: Alignment.center,
92+
child: Column(children: [
93+
Visibility(
94+
visible: viewModel.showSettings,
95+
child: const Column(
96+
children: [
97+
OpenAiSetting(),
98+
SizedBox(
99+
height: 20,
100+
),
101+
],
102+
),
114103
),
115-
onTap: () {
116-
viewModel.send(context);
117-
},
118-
),
104+
OutBorderTextFormField(
105+
hintText: 'Message ChatGPT...',
106+
controller: viewModel.controller,
107+
textInputAction: TextInputAction.send,
108+
textStyle: const TextStyle(color: Colors.white),
109+
focusColor: GlobalColors.success,
110+
onFieldSubmitted: (value) {
111+
viewModel.send(context);
112+
},
113+
suffixWidget: InkWell(
114+
child: Icon(
115+
Icons.send,
116+
color: viewModel.isLoading
117+
? GlobalColors.border
118+
: GlobalColors.success,
119+
),
120+
onTap: () {
121+
viewModel.send(context);
122+
},
123+
),
124+
),
125+
SizedBox(
126+
height: 10,
127+
)
128+
]),
119129
),
120-
]),
121-
),
130+
],
131+
))
122132
],
123133
);
124134
}
@@ -235,6 +245,18 @@ class ContentPage extends BaseStlessWidget<ChatGptProvider> {
235245
label: const Text(
236246
'Save Image',
237247
style: TextStyle(color: Colors.white),
248+
)),
249+
const Spacer(),
250+
TextButton.icon(
251+
onPressed: () async {},
252+
icon: const Icon(
253+
Icons.refresh,
254+
color: GlobalColors.success,
255+
size: 16,
256+
),
257+
label: const Text(
258+
'Refresh',
259+
style: TextStyle(color: Colors.white),
238260
))
239261
],
240262
)
@@ -247,99 +269,77 @@ class ContentPage extends BaseStlessWidget<ChatGptProvider> {
247269
);
248270
}
249271

250-
_toolsWidget(BuildContext ctx, ChatGptProvider viewModel) {
251-
UserEntity? loginUser = ctx.watch<StoreProvider>().user;
272+
_buildLeftNavigation(BuildContext context, ChatGptProvider viewModel) {
273+
UserEntity? loginUser = context.watch<StoreProvider>().user;
252274
String avatar = loginUser != null ? (loginUser.avatar ?? '') : '';
253275

254-
return Container(
255-
width: 80,
256-
padding: const EdgeInsets.symmetric(vertical: 30),
257-
decoration: BoxDecoration(
258-
color: const Color(0xFF45454e),
259-
borderRadius: BorderRadius.circular(10),
260-
border: Border.all(color: GlobalColors.gray, width: 1)),
261-
child: Column(
262-
mainAxisSize: MainAxisSize.min,
263-
children: [
264-
InkWell(
265-
child: SvgPicture.asset(
266-
'assets/logo/logo_white.svg',
267-
width: 35,
268-
height: 35,
269-
),
270-
onTap: () {
271-
Navigator.of(ctx).pop();
272-
},
273-
),
274-
const SizedBox(
275-
height: 10,
276-
),
277-
const Divider(
278-
color: GlobalColors.border,
279-
indent: 20,
280-
endIndent: 20,
281-
),
282-
const SizedBox(
283-
height: 10,
284-
),
285-
IconButton(
286-
onPressed: () {
287-
ctx.read<ChatGptProvider>().startNewChat(ctx);
288-
},
289-
icon: const Icon(
290-
Icons.add_circle_outline,
291-
color: Colors.white,
292-
size: 30,
293-
)),
294-
const SizedBox(
295-
height: 10,
276+
return NavigationRail(
277+
elevation: 1,
278+
backgroundColor: Color(0xFF45454e),
279+
leading: SizedBox(
280+
height: 100,
281+
child: InkWell(
282+
child: SvgPicture.asset(
283+
'assets/logo/logo_white.svg',
284+
width: 35,
285+
height: 35,
296286
),
297-
IconButton(
298-
onPressed: () {
299-
viewModel.toggleConversation(ctx);
300-
},
301-
icon: const Icon(
302-
Icons.history,
303-
color: Colors.white,
304-
size: 30,
305-
)),
306-
const SizedBox(
307-
height: 10,
308-
),
309-
IconButton(
310-
onPressed: () {
311-
viewModel.toggleSetting(ctx);
287+
onTap: () {
288+
Navigator.of(context).pop();
289+
},
290+
),
291+
),
292+
trailing: Expanded(
293+
child: Column(
294+
children: [
295+
Spacer(),
296+
InkWell(
297+
child: CircleAvatar(
298+
backgroundImage: (avatar != null && avatar.isNotEmpty
299+
? NetworkImage(avatar)
300+
: const AssetImage('assets/user/user-02.png'))
301+
as ImageProvider,
302+
radius: 20,
303+
),
304+
onTap: () {
305+
Navigator.of(context).pushNamed('/profile');
312306
},
313-
icon: const Icon(
314-
Icons.settings,
315-
color: Colors.white,
316-
size: 30,
317-
)),
318-
const SizedBox(
319-
height: 10,
320-
),
321-
const Divider(
322-
color: GlobalColors.border,
323-
indent: 20,
324-
endIndent: 20,
325-
),
326-
const SizedBox(
327-
height: 10,
328-
),
329-
InkWell(
330-
child: CircleAvatar(
331-
backgroundImage: (avatar != null && avatar.isNotEmpty
332-
? NetworkImage(avatar)
333-
: const AssetImage('assets/user/user-02.png'))
334-
as ImageProvider,
335-
radius: 20,
336307
),
337-
onTap: () {
338-
Navigator.of(ctx).pushNamed('/profile');
339-
},
340-
)
341-
],
308+
SizedBox(
309+
height: 20,
310+
)
311+
],
312+
),
342313
),
314+
extended: false,
315+
onDestinationSelected: (index) {
316+
return _onDestinationSelected(context, index, viewModel);
317+
},
318+
destinations: viewModel.destinations,
319+
labelType: NavigationRailLabelType.all,
320+
selectedIndex: viewModel.selectedIndex,
321+
unselectedLabelTextStyle: TextStyle(color: Colors.white),
322+
selectedLabelTextStyle: TextStyle(color: GlobalColors.success),
323+
selectedIconTheme: IconThemeData(color: GlobalColors.success),
324+
unselectedIconTheme: IconThemeData(color: Colors.white),
325+
useIndicator: false,
343326
);
344327
}
328+
329+
void _onDestinationSelected(
330+
BuildContext context, int index, ChatGptProvider viewModel) {
331+
viewModel.selectedIndex = index;
332+
if (index == 0) {
333+
viewModel.hideSetting(context);
334+
viewModel.hideConversation(context);
335+
viewModel.startNewChat(context);
336+
337+
} else if (index == 1) {
338+
viewModel.toggleConversation(context);
339+
viewModel.hideSetting(context);
340+
} else if (index == 6) {
341+
viewModel.hideConversation(context);
342+
viewModel.toggleSetting(context);
343+
}
344+
}
345345
}

0 commit comments

Comments
 (0)