2022-10-22 02:17:30 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
class CommentModal extends StatefulWidget {
|
|
|
|
final String? comment;
|
|
|
|
final void Function(String) onConfirm;
|
2023-05-01 03:48:23 +02:00
|
|
|
final bool dialog;
|
2022-10-22 02:17:30 +02:00
|
|
|
|
|
|
|
const CommentModal({
|
|
|
|
Key? key,
|
|
|
|
this.comment,
|
2023-05-01 03:48:23 +02:00
|
|
|
required this.onConfirm,
|
|
|
|
required this.dialog
|
2022-10-22 02:17:30 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<CommentModal> createState() => _CommentModalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CommentModalState extends State<CommentModal> {
|
|
|
|
final TextEditingController commentController = TextEditingController();
|
|
|
|
|
|
|
|
bool validData = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
if (widget.comment != null) {
|
|
|
|
commentController.text = widget.comment!.replaceFirst(RegExp(r'#(\s)?'), "");
|
|
|
|
}
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-01 03:48:23 +02:00
|
|
|
Widget content() {
|
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2023-05-01 04:49:40 +02:00
|
|
|
Flexible(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Wrap(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 24),
|
|
|
|
child: Icon(
|
|
|
|
Icons.comment_rounded,
|
|
|
|
size: 24,
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
2023-05-01 03:48:23 +02:00
|
|
|
),
|
2023-05-01 04:49:40 +02:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
AppLocalizations.of(context)!.comment,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface
|
|
|
|
),
|
2023-05-01 03:48:23 +02:00
|
|
|
),
|
2023-05-01 04:49:40 +02:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
child: TextFormField(
|
|
|
|
controller: commentController,
|
|
|
|
onChanged: (value) {
|
|
|
|
if (value != '') {
|
|
|
|
setState(() => validData = true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setState(() => validData = false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.comment_rounded),
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(10)
|
|
|
|
)
|
2022-10-22 02:17:30 +02:00
|
|
|
),
|
2023-05-01 04:49:40 +02:00
|
|
|
labelText: AppLocalizations.of(context)!.comment,
|
|
|
|
helperText: AppLocalizations.of(context)!.commentsDescription,
|
|
|
|
helperMaxLines: 3
|
|
|
|
)
|
2022-10-22 02:17:30 +02:00
|
|
|
),
|
|
|
|
),
|
2023-05-01 04:49:40 +02:00
|
|
|
],
|
|
|
|
),
|
2023-05-01 03:48:23 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
child: Text(AppLocalizations.of(context)!.cancel)
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
TextButton(
|
|
|
|
onPressed: validData == true
|
|
|
|
? () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
widget.onConfirm("# ${commentController.text}");
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.confirm,
|
|
|
|
style: TextStyle(
|
|
|
|
color: validData == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.grey
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widget.dialog == true) {
|
|
|
|
return Dialog(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(
|
|
|
|
maxWidth: 400
|
|
|
|
),
|
|
|
|
child: content()
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Padding(
|
|
|
|
padding: MediaQuery.of(context).viewInsets,
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(28),
|
|
|
|
topRight: Radius.circular(28)
|
|
|
|
),
|
|
|
|
color: Theme.of(context).dialogBackgroundColor
|
|
|
|
),
|
|
|
|
child: content()
|
2022-10-22 02:17:30 +02:00
|
|
|
),
|
2023-05-01 03:48:23 +02:00
|
|
|
);
|
|
|
|
}
|
2022-10-22 02:17:30 +02:00
|
|
|
}
|
|
|
|
}
|