Skip to content

Commit

Permalink
update chatgpt page
Browse files Browse the repository at this point in the history
  • Loading branch information
logan committed May 24, 2024
1 parent 24416cc commit 2bcb185
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 146 deletions.
5 changes: 4 additions & 1 deletion flareline_uikit/lib/widget/flareline_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ abstract class FlarelineLayoutWidget extends StatelessWidget {

Color? get backgroundColor => null;

EdgeInsetsGeometry? get padding =>
const EdgeInsets.symmetric(horizontal: 20, vertical: 16);

Widget? toolbarWidget(BuildContext context, bool showDrawer) {
return null;
}
Expand Down Expand Up @@ -107,7 +110,7 @@ abstract class FlarelineLayoutWidget extends StatelessWidget {
width: double.maxFinite,
height: double.maxFinite,
alignment: isAlignCenter ? Alignment.center : null,
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
padding: padding,
child: isContentScroll
? SingleChildScrollView(child: contentWidget)
: contentWidget,
Expand Down
1 change: 1 addition & 0 deletions lib/entity/message_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MessageEntity {
late int timestamp;
late String belongUid;
late String conversationId;
late String fromMessageId;

MessageEntity();

Expand Down
4 changes: 3 additions & 1 deletion lib/entity/message_entity.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

282 changes: 141 additions & 141 deletions lib/pages/chatgpt/chatgpt_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class ChatGptPage extends LayoutWidget {
// TODO: implement backgroundColor
Color? get backgroundColor => const Color(0xFF2b2b35);

@override
// TODO: implement padding
EdgeInsetsGeometry? get padding => null;

@override
Widget contentDesktopWidget(BuildContext context) {
return ContentPage();
Expand All @@ -56,69 +60,75 @@ class ContentPage extends BaseStlessWidget<ChatGptProvider> {
@override
Widget bodyWidget(
BuildContext context, ChatGptProvider viewModel, Widget? child) {
return Column(
return Row(
children: [
_buildLeftNavigation(context, viewModel),
Expanded(
child: Stack(
alignment: Alignment.topCenter,
children: [
_gptMessageWidget(context, viewModel),
Visibility(
visible: viewModel.showConversation,
child: ConversationPage(
onVisibleChanged: (visible) {
viewModel.showConversation = visible;
},
),
),
Align(
child: _toolsWidget(context, viewModel),
alignment: Alignment.centerLeft,
),
],
),
),
const SizedBox(
height: 20,
),
Container(
margin: EdgeInsets.symmetric(horizontal: margin),
alignment: Alignment.center,
child: Column(children: [
Visibility(
visible: viewModel.showSettings,
child: const Column(
child: Column(
children: [
SizedBox(height: 10,),
Expanded(
child: Stack(
alignment: Alignment.topCenter,
children: [
OpenAiSetting(),
SizedBox(
height: 20,
_gptMessageWidget(context, viewModel),
Visibility(
visible: viewModel.showConversation,
child: ConversationPage(
onVisibleChanged: (visible) {
viewModel.showConversation = visible;
},
),
),
],
),
),
OutBorderTextFormField(
hintText: 'Message ChatGPT...',
controller: viewModel.controller,
textInputAction: TextInputAction.send,
textStyle: const TextStyle(color: Colors.white),
focusColor: GlobalColors.success,
onFieldSubmitted: (value) {
viewModel.send(context);
},
suffixWidget: InkWell(
child: Icon(
Icons.send,
color: viewModel.isLoading
? GlobalColors.border
: GlobalColors.success,
const SizedBox(
height: 20,
),
Container(
margin: EdgeInsets.symmetric(horizontal: margin),
alignment: Alignment.center,
child: Column(children: [
Visibility(
visible: viewModel.showSettings,
child: const Column(
children: [
OpenAiSetting(),
SizedBox(
height: 20,
),
],
),
),
onTap: () {
viewModel.send(context);
},
),
OutBorderTextFormField(
hintText: 'Message ChatGPT...',
controller: viewModel.controller,
textInputAction: TextInputAction.send,
textStyle: const TextStyle(color: Colors.white),
focusColor: GlobalColors.success,
onFieldSubmitted: (value) {
viewModel.send(context);
},
suffixWidget: InkWell(
child: Icon(
Icons.send,
color: viewModel.isLoading
? GlobalColors.border
: GlobalColors.success,
),
onTap: () {
viewModel.send(context);
},
),
),
SizedBox(
height: 10,
)
]),
),
]),
),
],
))
],
);
}
Expand Down Expand Up @@ -235,6 +245,18 @@ class ContentPage extends BaseStlessWidget<ChatGptProvider> {
label: const Text(
'Save Image',
style: TextStyle(color: Colors.white),
)),
const Spacer(),
TextButton.icon(
onPressed: () async {},
icon: const Icon(
Icons.refresh,
color: GlobalColors.success,
size: 16,
),
label: const Text(
'Refresh',
style: TextStyle(color: Colors.white),
))
],
)
Expand All @@ -247,99 +269,77 @@ class ContentPage extends BaseStlessWidget<ChatGptProvider> {
);
}

_toolsWidget(BuildContext ctx, ChatGptProvider viewModel) {
UserEntity? loginUser = ctx.watch<StoreProvider>().user;
_buildLeftNavigation(BuildContext context, ChatGptProvider viewModel) {
UserEntity? loginUser = context.watch<StoreProvider>().user;
String avatar = loginUser != null ? (loginUser.avatar ?? '') : '';

return Container(
width: 80,
padding: const EdgeInsets.symmetric(vertical: 30),
decoration: BoxDecoration(
color: const Color(0xFF45454e),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: GlobalColors.gray, width: 1)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
child: SvgPicture.asset(
'assets/logo/logo_white.svg',
width: 35,
height: 35,
),
onTap: () {
Navigator.of(ctx).pop();
},
),
const SizedBox(
height: 10,
),
const Divider(
color: GlobalColors.border,
indent: 20,
endIndent: 20,
),
const SizedBox(
height: 10,
),
IconButton(
onPressed: () {
ctx.read<ChatGptProvider>().startNewChat(ctx);
},
icon: const Icon(
Icons.add_circle_outline,
color: Colors.white,
size: 30,
)),
const SizedBox(
height: 10,
return NavigationRail(
elevation: 1,
backgroundColor: Color(0xFF45454e),
leading: SizedBox(
height: 100,
child: InkWell(
child: SvgPicture.asset(
'assets/logo/logo_white.svg',
width: 35,
height: 35,
),
IconButton(
onPressed: () {
viewModel.toggleConversation(ctx);
},
icon: const Icon(
Icons.history,
color: Colors.white,
size: 30,
)),
const SizedBox(
height: 10,
),
IconButton(
onPressed: () {
viewModel.toggleSetting(ctx);
onTap: () {
Navigator.of(context).pop();
},
),
),
trailing: Expanded(
child: Column(
children: [
Spacer(),
InkWell(
child: CircleAvatar(
backgroundImage: (avatar != null && avatar.isNotEmpty
? NetworkImage(avatar)
: const AssetImage('assets/user/user-02.png'))
as ImageProvider,
radius: 20,
),
onTap: () {
Navigator.of(context).pushNamed('/profile');
},
icon: const Icon(
Icons.settings,
color: Colors.white,
size: 30,
)),
const SizedBox(
height: 10,
),
const Divider(
color: GlobalColors.border,
indent: 20,
endIndent: 20,
),
const SizedBox(
height: 10,
),
InkWell(
child: CircleAvatar(
backgroundImage: (avatar != null && avatar.isNotEmpty
? NetworkImage(avatar)
: const AssetImage('assets/user/user-02.png'))
as ImageProvider,
radius: 20,
),
onTap: () {
Navigator.of(ctx).pushNamed('/profile');
},
)
],
SizedBox(
height: 20,
)
],
),
),
extended: false,
onDestinationSelected: (index) {
return _onDestinationSelected(context, index, viewModel);
},
destinations: viewModel.destinations,
labelType: NavigationRailLabelType.all,
selectedIndex: viewModel.selectedIndex,
unselectedLabelTextStyle: TextStyle(color: Colors.white),
selectedLabelTextStyle: TextStyle(color: GlobalColors.success),
selectedIconTheme: IconThemeData(color: GlobalColors.success),
unselectedIconTheme: IconThemeData(color: Colors.white),
useIndicator: false,
);
}

void _onDestinationSelected(
BuildContext context, int index, ChatGptProvider viewModel) {
viewModel.selectedIndex = index;
if (index == 0) {
viewModel.hideSetting(context);
viewModel.hideConversation(context);
viewModel.startNewChat(context);

} else if (index == 1) {
viewModel.toggleConversation(context);
viewModel.hideSetting(context);
} else if (index == 6) {
viewModel.hideConversation(context);
viewModel.toggleSetting(context);
}
}
}
Loading

0 comments on commit 2bcb185

Please sign in to comment.