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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ShadcnApp.router(
|
return ShadcnApp.router(
|
||||||
title: 'Flutter Demo',
|
title: 'TweetForge',
|
||||||
routerConfig: _router,
|
routerConfig: _router,
|
||||||
scaling: defaultTargetPlatform == TargetPlatform.android ? AdaptiveScaling.only(
|
scaling: defaultTargetPlatform == TargetPlatform.android ? AdaptiveScaling.only(
|
||||||
sizeScaling: 1,
|
sizeScaling: 1,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import 'package:path/path.dart' as path;
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:file_saver/file_saver.dart';
|
import 'package:file_saver/file_saver.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
// number formatter for engagement fields
|
// number formatter for engagement fields
|
||||||
class NumberTextInputFormatter extends TextInputFormatter {
|
class NumberTextInputFormatter extends TextInputFormatter {
|
||||||
@@ -276,14 +277,29 @@ class _HomePageState extends State<HomePage> {
|
|||||||
// genrate filename with timestmp
|
// genrate filename with timestmp
|
||||||
final fileName = "quote_${DateTime.now().millisecondsSinceEpoch}";
|
final fileName = "quote_${DateTime.now().millisecondsSinceEpoch}";
|
||||||
|
|
||||||
await FileSaver.instance.saveFile(
|
// On desktop platforms (macOS, Windows, Linux), use FilePicker to let user choose location
|
||||||
name: fileName,
|
if (!kIsWeb && (Platform.isMacOS || Platform.isWindows || Platform.isLinux)) {
|
||||||
bytes: postPreviewImage!,
|
String? outputPath = await FilePicker.platform.saveFile(
|
||||||
ext: "png",
|
dialogTitle: "Save Quote Image",
|
||||||
mimeType: MimeType.png,
|
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) {
|
} catch (e) {
|
||||||
print("Error downloadin image: $e");
|
print("Error downloadin image: $e");
|
||||||
}
|
}
|
||||||
@@ -1113,6 +1129,9 @@ class _HomePageState extends State<HomePage> {
|
|||||||
// optinal: log share result
|
// optinal: log share result
|
||||||
if (result.status == ShareResultStatus.success) {
|
if (result.status == ShareResultStatus.success) {
|
||||||
print("Share succesful");
|
print("Share succesful");
|
||||||
|
|
||||||
|
// Send Discord webhook notifiation
|
||||||
|
_sendShareNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} 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
|
// load form data from shared preferences
|
||||||
Future<void> _loadFormData() async {
|
Future<void> _loadFormData() async {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user