update base URL for QuoteGeneratorApiV2 to use localhost in debug mode
Some checks failed
Build Android App / build (push) Failing after 47s
Some checks failed
Build Android App / build (push) Failing after 47s
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<HomePage> {
|
||||
// genrate filename with timestmp
|
||||
final fileName = "quote_${DateTime.now().millisecondsSinceEpoch}";
|
||||
|
||||
// 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,
|
||||
);
|
||||
|
||||
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<HomePage> {
|
||||
// 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<HomePage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _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<void> _loadFormData() async {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user