From d8a1b741c621f07e29851bc2ca91ddf8e525e015 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 15 Aug 2021 13:32:19 +1000 Subject: [PATCH] Improve widget for submitting user feedback --- lib/l10n | 2 +- lib/settings/settings.dart | 42 +++------------ lib/widget/submit_feedback.dart | 94 +++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 36 deletions(-) create mode 100644 lib/widget/submit_feedback.dart diff --git a/lib/l10n b/lib/l10n index ad2e43ea..c81c1c79 160000 --- a/lib/l10n +++ b/lib/l10n @@ -1 +1 @@ -Subproject commit ad2e43ea5e105b776e9eba81f0295cfda2cb0451 +Subproject commit c81c1c79d18a7304761a30adb15090017a613157 diff --git a/lib/settings/settings.dart b/lib/settings/settings.dart index 8a0556cd..75cfb0fc 100644 --- a/lib/settings/settings.dart +++ b/lib/settings/settings.dart @@ -9,6 +9,7 @@ import 'package:inventree/widget/dialogs.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:inventree/l10.dart'; +import 'package:inventree/widget/submit_feedback.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -129,43 +130,14 @@ class _InvenTreeSettingsState extends State { }); } - void _sendReport(BuildContext context, String message) async { - bool result = await sentryReportMessage(message); - - if (result) { - showSnackIcon( - L10().feedbackSuccess, - success: true, - ); - } else { - showSnackIcon( - L10().feedbackError, - success: false, - ); - } - } - void _submitFeedback(BuildContext context) async { - TextEditingController _controller = TextEditingController(); - - _controller.clear(); - - showFormDialog( - L10().submitFeedback, - key: _feedbackKey, - callback: () { - _sendReport(context, _controller.text); - }, - fields: [ - TextField( - decoration: InputDecoration( - ), - keyboardType: TextInputType.multiline, - maxLines: null, - controller: _controller - ) - ] + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => SubmitFeedbackWidget(), + ) ); } + } \ No newline at end of file diff --git a/lib/widget/submit_feedback.dart b/lib/widget/submit_feedback.dart new file mode 100644 index 00000000..a4f60787 --- /dev/null +++ b/lib/widget/submit_feedback.dart @@ -0,0 +1,94 @@ + + +import 'package:email_validator/email_validator.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:inventree/inventree/sentry.dart'; +import 'package:inventree/widget/snacks.dart'; + +import '../l10.dart'; + +class SubmitFeedbackWidget extends StatefulWidget { + + @override + _SubmitFeedbackState createState() => _SubmitFeedbackState(); + +} + + +class _SubmitFeedbackState extends State { + + final _formkey = new GlobalKey(); + + String message = ""; + + @override + Widget build(BuildContext context) { + + return Scaffold( + appBar: AppBar( + title: Text(L10().submitFeedback), + actions: [ + IconButton( + icon: FaIcon(FontAwesomeIcons.paperPlane), + onPressed: () async { + if (_formkey.currentState!.validate()) { + _formkey.currentState!.save(); + + // Upload + bool result = await sentryReportMessage(message); + + if (result) { + showSnackIcon( + L10().feedbackSuccess, + success: true, + ); + } else { + showSnackIcon( + L10().feedbackError, + success: false + ); + } + + // Exit + Navigator.of(context).pop(); + } + }, + ) + ], + ), + body: Form( + key: _formkey, + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextFormField( + decoration: InputDecoration( + labelText: L10().feedback, + labelStyle: TextStyle(fontWeight: FontWeight.bold), + ), + maxLines: null, + keyboardType: TextInputType.multiline, + validator: (value) { + if (value == null || value.trim().isEmpty) { + return L10().valueCannotBeEmpty; + } + }, + onSaved: (value) { + if (value != null) { + message = value; + } + }, + ), + ], + ) + ) + ) + ); + } + +} \ No newline at end of file