Updated feedback to include screenshot and drawings

This commit is contained in:
2024-03-16 21:28:28 +01:00
parent eb361febf8
commit 7b3c0b4885
17 changed files with 186 additions and 111 deletions

View File

@ -1,78 +0,0 @@
import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart';
import '../../../../api/mhsl/server/feedback/addFeedback.dart';
import '../../../../api/mhsl/server/feedback/addFeedbackParams.dart';
import '../../../../model/accountData.dart';
import '../../../../widget/infoDialog.dart';
class FeedbackDialog extends StatefulWidget {
const FeedbackDialog({super.key});
@override
State<FeedbackDialog> createState() => _FeedbackDialogState();
}
class _FeedbackDialogState extends State<FeedbackDialog> {
final TextEditingController _feedbackInput = TextEditingController();
String? _error;
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text("Feedback"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Feedback, Anregungen, Ideen, Fehler und Verbesserungen"),
const SizedBox(height: 10),
const Text("Bitte gib keine geheimen Daten wie z.B. Passwörter weiter.", style: TextStyle(fontSize: 10)),
const SizedBox(height: 10),
TextField(
controller: _feedbackInput,
autofocus: true,
decoration: const InputDecoration(
border: OutlineInputBorder(),
label: Text("Feedback und Verbesserungen")
),
// style: TextStyle(),
// expands: true,
minLines: 3,
maxLines: 5,
),
Visibility(
visible: _error != null,
child: Text("Senden fehlgeschlagen: $_error", style: const TextStyle(color: Colors.red))
)
],
),
actions: [
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text("Abbrechen")),
TextButton(
onPressed: () async {
AddFeedback(
AddFeedbackParams(
user: AccountData().getUserSecret(),
feedback: _feedbackInput.text,
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber)
)
)
.run()
.then((value) {
Navigator.of(context).pop();
InfoDialog.show(context, "Danke für dein Feedback!");
})
.catchError((error, trace) {
setState(() {
_error = error.toString();
});
});
},
child: const Text("Senden"),
)
],
);
}
}

View File

@ -0,0 +1,99 @@
import 'package:flutter/material.dart';
import '../../../../theming/darkAppTheme.dart';
import '../../../../widget/loadingSpinner.dart';
class FeedbackForm extends StatefulWidget {
final Future<void> Function(String, {Map<String, dynamic>? extras}) callback;
final ScrollController? scrollController;
const FeedbackForm({required this.scrollController, required this.callback, super.key});
@override
State<FeedbackForm> createState() => _FeedbackFormState();
}
class _FeedbackFormState extends State<FeedbackForm> {
final TextEditingController _feedbackInput = TextEditingController();
bool _textFieldEmpty = false;
bool _isSending = false;
@override
void initState() {
super.initState();
_feedbackInput.addListener(() {
setState(() {
_textFieldEmpty = _feedbackInput.text.isEmpty;
});
});
}
@override
Widget build(BuildContext context) {
return Theme(
data: DarkAppTheme.theme,
child: Visibility(
visible: !_isSending,
replacement: const LoadingSpinner(infoText: "Daten werden ermittelt"),
child: SingleChildScrollView(
controller: widget.scrollController,
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Bitte gib keine geheimen Daten wie z.B. Passwörter weiter!", style: TextStyle(fontSize: 10)),
const SizedBox(height: 10),
TextField(
controller: _feedbackInput,
autofocus: true,
decoration: InputDecoration(
border: const OutlineInputBorder(),
label: const Text("Dein Feedback"),
errorText: _textFieldEmpty ? "Bitte gib eine Beschreibung an" : null
),
minLines: 1,
maxLines: 2,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () async {
if(_isSending) return;
if(_feedbackInput.text.isEmpty) {
setState(() {
_textFieldEmpty = true;
});
return;
}
setState(() {
_isSending = true;
});
widget.callback(_feedbackInput.text);
},
child: const Text("Senden"),
),
],
),
const SizedBox(height: 40),
const Center(
child: Column(
children: [
Text(
"Feedback, mal süß wie Kuchen, mal sauer wie Gurken, doch immer ein Schlüssel fürs Wachsen und Lernen.",
textAlign: TextAlign.center,
),
SizedBox(height: 10),
Icon(Icons.emoji_objects_outlined)
],
)
),
],
),
),
),
);
}
}

View File

@ -0,0 +1,32 @@
import 'dart:convert';
import 'package:feedback/feedback.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:loader_overlay/loader_overlay.dart';
import 'package:package_info/package_info.dart';
import '../../../../api/mhsl/server/feedback/addFeedback.dart';
import '../../../../api/mhsl/server/feedback/addFeedbackParams.dart';
import '../../../../model/accountData.dart';
import '../../../../widget/infoDialog.dart';
class FeedbackSender {
static send(BuildContext context, UserFeedback feedback) async {
BetterFeedback.of(context).hide();
context.loaderOverlay.show();
AddFeedbackParams params = AddFeedbackParams(
user: AccountData().getUserSecret(),
feedback: feedback.text,
screenshot: await compute((message) => base64Encode(message), feedback.screenshot),
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber)
);
AddFeedback(params).run().then((value) {
InfoDialog.show(context, "Danke für dein Feedback!");
context.loaderOverlay.hide();
}).catchError((error, trace) {
InfoDialog.show(context, error.toString());
context.loaderOverlay.hide();
});
}
}