import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.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/filePick.dart'; import '../../../../widget/infoDialog.dart'; class FeedbackDialog extends StatefulWidget { const FeedbackDialog({super.key}); @override State createState() => _FeedbackDialogState(); } class _FeedbackDialogState extends State { final ImagePicker picker = ImagePicker(); final TextEditingController _feedbackInput = TextEditingController(); Uint8List? _image; String? _error; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Feedback'), ), body: Column( mainAxisSize: MainAxisSize.max, children: [ const SizedBox(height: 5), const Text('Feedback, Anregungen, Ideen, Fehler und Verbesserungen', textAlign: TextAlign.center), const SizedBox(height: 15), const Text('Bitte gib keine geheimen Daten wie z.B. Passwörter weiter.', textAlign: TextAlign.center, style: TextStyle(fontSize: 11)), const SizedBox(height: 20), Padding( padding: const EdgeInsets.all(10), child: TextField( controller: _feedbackInput, autofocus: true, decoration: const InputDecoration( border: OutlineInputBorder(), label: Text('Feedback und Verbesserungen'), ), // style: TextStyle(), // expands: true, minLines: 4, maxLines: 7, ), ), if(_image != null) Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(5)), border: Border.all( width: 3, color: Theme.of(context).primaryColor, ), ), height: 150, child: Image( image: Image.memory(_image!).image, fit: BoxFit.contain, ), ), Visibility( visible: _error != null, child: Text('Senden fehlgeschlagen: $_error', style: const TextStyle(color: Colors.red)), ), Padding( padding: const EdgeInsets.only(right: 20, left: 10), child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ IconButton( onPressed: () async { context.loaderOverlay.show(); var imageData = await (await FilePick.galleryPick())?.readAsBytes(); context.loaderOverlay.hide(); setState(() { _image = imageData; }); }, icon: const Icon(Icons.attach_file_outlined), ), const Expanded(child: SizedBox.shrink()), TextButton( onPressed: () async { context.loaderOverlay.show(); AddFeedback( AddFeedbackParams( user: AccountData().getUserSecret(), feedback: _feedbackInput.text, screenshot: _image != null ? base64Encode(_image!) : null, appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber), ) ).run().then((value) { Navigator.of(context).pop(); InfoDialog.show(context, 'Danke für dein Feedback!'); context.loaderOverlay.hide(); }).catchError((error, trace) { setState(() { _error = error.toString(); }); context.loaderOverlay.hide(); }); }, child: const Text('Senden'), ) ] ) ) ], ), ); /* return Scaffold( appBar: AppBar( title: const Text('Raumplan'), ), body: PhotoView( imageProvider: Image.asset('assets/img/raumplan.jpg').image, minScale: 0.5, maxScale: 2.0, backgroundDecoration: BoxDecoration(color: Theme.of(context).colorScheme.background), ), ); */ /* 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'), ) ], ); */ } }