Skip to content

Commit

Permalink
feat: alternative implentation to share conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
ous50 committed Jan 9, 2024
1 parent b9594fd commit cd0760f
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 56 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
3 changes: 2 additions & 1 deletion lib/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:sydney_webui/models/message.dart';
import 'package:sydney_webui/services/sharegpt_service.dart';
import 'package:sydney_webui/services/sydney_service.dart';
import 'package:sydney_webui/widgets/share_conversation_dialog.dart';
import 'package:sydney_webui/utils/url.dart';

class Controller extends GetxController {
// Constants
Expand Down Expand Up @@ -300,7 +301,7 @@ class Controller extends GetxController {
try {
final id = await shareGptService.uploadConversation(messages);
final url = 'https://shareg.pt/$id';
await Get.dialog(ShareConversationDialog(shareGptUrl: url));
Get.dialog(ShareConversationDialog(sharegptUrl: url,));
} catch (e) {
Get.snackbar('Error occurred', 'Failed to share conversation: $e');
}
Expand Down
162 changes: 139 additions & 23 deletions lib/widgets/share_conversation_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,146 @@
import 'package:flutter/material.dart';
import 'package:sydney_webui/utils/copy.dart';
import 'package:flutter/services.dart';
import 'package:sydney_webui/utils/url.dart';
import 'package:share_plus/share_plus.dart';

class ShareConversationDialog extends StatelessWidget {
final String shareGptUrl;
final String sharegptUrl;

const ShareConversationDialog({Key? key, required this.shareGptUrl})
: super(key: key);
const ShareConversationDialog({Key? key, required this.sharegptUrl}) : super(key: key);

@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text("ShareGPT URL"),
content: SelectableText(shareGptUrl),
actions: [
IconButton(
icon: const Icon(Icons.copy_rounded),
onPressed: () => copyContent(shareGptUrl),
tooltip: "Copy URL",
),
IconButton(
icon: const Icon(Icons.open_in_browser_rounded),
onPressed: () => openUrl(shareGptUrl),
tooltip: "Open URL",
)
],
);
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('Share Conversation'),
content: Text(sharegptUrl),
actions: [
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
ElevatedButton(
onPressed: () {
Clipboard.setData(ClipboardData(text: sharegptUrl));
},
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.copy),
Text('Copy')
],
)
),
SizedBox(width: 8),
ElevatedButton(
onPressed: () {
openUrl(sharegptUrl);
},
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.open_in_browser),
Text('Open')
],
)
),
SizedBox(width: 8),
ElevatedButton(
onPressed: () {
Share.share(sharegptUrl);
},
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.share),
Text('Share')
],
)
)
],
),
)
// SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Row(
// children: [
// ElevatedButton(
// onPressed: () {
// Clipboard.setData(ClipboardData(text: sharegptUrl));
// },
// child: const Row(
// mainAxisSize: MainAxisSize.min,
// children: [
// Icon(Icons.copy),
// Text('Copy')
// ],
// )
// ),
// // SizedBox(height: 8),
// ElevatedButton(
// onPressed: () {
// openUrl(sharegptUrl);
// },
// child: const Row(
// mainAxisSize: MainAxisSize.min,
// children: [
// Icon(Icons.open_in_browser),
// Text('Open')
// ],
// )
// ),
// // SizedBox(height: 8),
// ElevatedButton(
// onPressed: () {
// Share.share(sharegptUrl);
// },
// child: const Row(
// mainAxisSize: MainAxisSize.min,
// children: [
// Icon(Icons.share),
// Text('Share')
// ],
// )
// )

// ElevatedButton(
// onPressed: () {
// Clipboard.setData(ClipboardData(text: sharegptUrl));
// },
// child: const Row(
// mainAxisSize: MainAxisSize.min,
// children: [
// Icon(Icons.copy),
// Text('Copy')
// ],
// )
// ),
// // SizedBox(height: 8),
// ElevatedButton(
// onPressed: () {
// openUrl(sharegptUrl);
// },
// child: const Row(
// mainAxisSize: MainAxisSize.min,
// children: [
// Icon(Icons.open_in_browser),
// Text('Open')
// ],
// )
// ),
// // SizedBox(height: 8),
// ElevatedButton(
// onPressed: () {
// Share.share(sharegptUrl);
// },
// child: const Row(
// mainAxisSize: MainAxisSize.min,
// children: [
// Icon(Icons.share),
// Text('Share')
// ],
// )
// )
],
);
}
}
Loading

0 comments on commit cd0760f

Please sign in to comment.