Added copy-curl button
This commit is contained in:
parent
3ae2742033
commit
038287ba4c
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
@ -95,6 +96,14 @@ class _SendRootPageState extends State<SendRootPage> {
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
UI.buttonIconOnly(
|
||||
icon: FontAwesomeIcons.webhook,
|
||||
onPressed: _copyCurl,
|
||||
square: true,
|
||||
color: Theme.of(context).colorScheme.secondary.withAlpha(128),
|
||||
iconColor: Theme.of(context).colorScheme.onSecondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: UI.button(
|
||||
text: 'Send',
|
||||
@ -188,6 +197,14 @@ class _SendRootPageState extends State<SendRootPage> {
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
UI.buttonIconOnly(
|
||||
icon: FontAwesomeIcons.webhook,
|
||||
onPressed: _copyCurl,
|
||||
square: true,
|
||||
color: Theme.of(context).colorScheme.secondary.withAlpha(128),
|
||||
iconColor: Theme.of(context).colorScheme.onSecondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: UI.button(
|
||||
text: 'Send',
|
||||
@ -332,4 +349,35 @@ class _SendRootPageState extends State<SendRootPage> {
|
||||
_senderName.text = Globals().deviceName;
|
||||
});
|
||||
}
|
||||
|
||||
void _copyCurl() {
|
||||
final userAcc = Provider.of<AppAuth>(context, listen: false);
|
||||
|
||||
if (!userAcc.isAuth()) {
|
||||
Toaster.error("Error", 'Must be logged in to send messages');
|
||||
return;
|
||||
}
|
||||
|
||||
String curl = 'curl';
|
||||
curl += ' --data user_id="${userAcc.userID}"';
|
||||
curl += ' --data key="${userAcc.tokenSend}"';
|
||||
curl += ' --data title="${shellEscape(_msgTitle.text)}"';
|
||||
curl += ' --data content="${shellEscape(_msgContent.text)}"';
|
||||
|
||||
if (_expanded) {
|
||||
curl += ' --data channel="${shellEscape(_channelName.text)}"';
|
||||
curl += ' --data sender_name="${shellEscape(_senderName.text)}"';
|
||||
curl += ' --data priority="${_priority}"';
|
||||
}
|
||||
|
||||
curl += ' "https://simplecloudnotifier.de/"';
|
||||
|
||||
Clipboard.setData(new ClipboardData(text: curl));
|
||||
Toaster.info("Clipboard", 'Copied curl-command to Clipboard');
|
||||
print('================= [CLIPBOARD] =================\n${curl}\n================= [/CLIPBOARD] =================');
|
||||
}
|
||||
|
||||
String shellEscape(String str) {
|
||||
return str.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '\\n').replaceAll('\t', '\\t');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user