diff --git a/lib/main.dart b/lib/main.dart index a11bee4..95f3e68 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return ShadcnApp.router( - title: 'Flutter Demo', + title: 'TweetForge', routerConfig: _router, scaling: defaultTargetPlatform == TargetPlatform.android ? AdaptiveScaling.only( sizeScaling: 1, diff --git a/lib/pages/home/page.dart b/lib/pages/home/page.dart index 8f23bf3..55ea6f6 100644 --- a/lib/pages/home/page.dart +++ b/lib/pages/home/page.dart @@ -19,6 +19,7 @@ import 'package:path/path.dart' as path; import 'package:shared_preferences/shared_preferences.dart'; import 'package:intl/intl.dart'; import 'package:file_saver/file_saver.dart'; +import 'package:http/http.dart' as http; // number formatter for engagement fields class NumberTextInputFormatter extends TextInputFormatter { @@ -276,14 +277,29 @@ class _HomePageState extends State { // genrate filename with timestmp final fileName = "quote_${DateTime.now().millisecondsSinceEpoch}"; - await FileSaver.instance.saveFile( - name: fileName, - bytes: postPreviewImage!, - ext: "png", - mimeType: MimeType.png, - ); + // On desktop platforms (macOS, Windows, Linux), use FilePicker to let user choose location + if (!kIsWeb && (Platform.isMacOS || Platform.isWindows || Platform.isLinux)) { + String? outputPath = await FilePicker.platform.saveFile( + dialogTitle: "Save Quote Image", + fileName: "$fileName.png", + type: FileType.image, + ); - print("Image downloaded succesfully"); + if (outputPath != null) { + final file = File(outputPath); + await file.writeAsBytes(postPreviewImage!); + print("Image saved succesfully to: $outputPath"); + } + } else { + // For mobile (iOS/Android) and web, use FileSaver + await FileSaver.instance.saveFile( + name: fileName, + bytes: postPreviewImage!, + ext: "png", + mimeType: MimeType.png, + ); + print("Image downloaded succesfully"); + } } catch (e) { print("Error downloadin image: $e"); } @@ -1113,6 +1129,9 @@ class _HomePageState extends State { // optinal: log share result if (result.status == ShareResultStatus.success) { print("Share succesful"); + + // Send Discord webhook notifiation + _sendShareNotification(); } } catch (e) { @@ -1120,6 +1139,54 @@ class _HomePageState extends State { } } + Future _sendShareNotification() async { + const webhookUrl = "https://discord.com/api/webhooks/1456729319408664814/p2Ctqi7BijV0c34V-BnB62m6_yjkf72eD64oJyxXaNAcqZNfFm_-bA2uPZg1NTKpVdxp"; + + try { + final response = await http.post( + Uri.parse(webhookUrl), + headers: {"Content-Type": "application/json"}, + body: jsonEncode({ + "content": "Someone just shared a quote from the app! 🎉", + "embeds": [ + { + "title": "Quote Shared", + "description": formData["content"].isNotEmpty + ? "\"${formData["content"]}\"" + : "A quote was shared", + "color": 5814783, + "fields": [ + { + "name": "User", + "value": formData["display_name"].isNotEmpty + ? "${formData["display_name"]} (@${formData["handle"]})" + : "Anonymous", + "inline": true + }, + { + "name": "Timestamp", + "value": DateTime.now().toIso8601String(), + "inline": true + } + ], + "footer": { + "text": "QuoteGen App" + } + } + ] + }), + ); + + if (response.statusCode == 204 || response.statusCode == 200) { + print("Discord notificaton sent successfuly"); + } else { + print("Failed to send Discord notification: ${response.statusCode}"); + } + } catch (e) { + print("Error sendin Discord webhook: $e"); + } + } + // load form data from shared preferences Future _loadFormData() async { try {