import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:get_it/get_it.dart';
import 'package:keen_app_consumer/blocs/rating/rating_bloc.dart';
import 'package:keen_app_consumer/config/app_config.dart';
import 'package:keen_app_consumer/di/modules/base_scope/router/module_router.dart';
import 'package:keen_core/keen_core.dart';
import 'package:keen_app_consumer/di/modules/base_scope/router/webview/module_webview_route.dart';
class TransactionHistoryDetailsFeedbackPage extends StatefulWidget {
const TransactionHistoryDetailsFeedbackPage({
required this.transactionId,
required this.sessionType,
super.key,
});
final int transactionId;
final int sessionType;
@override
State<TransactionHistoryDetailsFeedbackPage> createState() =>
_TransactionHistoryDetailsFeedbackPageState();
}
class _TransactionHistoryDetailsFeedbackPageState
extends State<TransactionHistoryDetailsFeedbackPage> {
bool _isEnabled = false;
String? _comment;
late final TextEditingController controller;
static const int _kMaxCharacters = 700;
@override
void initState() {
controller = TextEditingController();
super.initState();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final appLocalizations = AppLocalizations.of(context)!;
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 20,
),
Text(
appLocalizations.technical_problems,
style: context.body1Bold,
),
const SizedBox(
height: 20,
),
Text(
appLocalizations.tell_us_what_went_wrong,
style: context.body1,
),
const SizedBox(
height: 20,
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.fromLTRB(20, 5, 5, 0),
child: Text(
appLocalizations.comments,
style: context.itemGreyTitle,
),
),
),
const SizedBox(
height: 5,
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0,
),
child: Container(
margin: const EdgeInsets.fromLTRB(20, 0, 20, 10),
child: _FeedbackTextField(
controller: controller,
maxLenght: _kMaxCharacters,
onChanged: (comment) {
setState(() {
_comment = comment;
_isEnabled = comment.isNotEmpty;
setState(() {});
});
}),
),
/*child: TextField(
maxLines: 8,
onChanged: (comment) {
_comment = comment;
_isEnabled = comment.isNotEmpty;
setState(() {});
},
decoration: InputDecoration.collapsed(
hintText: appLocalizations.commments_text_area,
),
),*/
),
const Spacer(),
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
margin: const EdgeInsets.all(20),
child: PrimaryButton(
text: appLocalizations.send_comments,
enable: _isEnabled,
onPressed: () {
context.read<RatingBloc>().add(
NegativeRatingEvent(
sessionId: widget.transactionId,
sessionType: widget.sessionType,
comment: _comment,
),
);
context.pop();
},
),
),
),
const SizedBox(
height: 10,
),
const _PolicyTextButtons(),
/* Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(appLocalizations.comments_policy),
Text(appLocalizations.user_agreement),
],
),*/
const SizedBox(
height: 10,
),
],
);
}
}
/*class _PolicyTextButtons extends StatelessWidget {
const _PolicyTextButtons();
}*/
class _FeedbackTextField extends StatelessWidget {
const _FeedbackTextField({
required this.controller,
required this.onChanged,
required this.maxLenght,
});
final TextEditingController controller;
final Function(String) onChanged;
final int maxLenght;
@override
Widget build(BuildContext context) {
return TextFormField(
onChanged: onChanged,
controller: controller,
keyboardType: TextInputType.multiline,
inputFormatters: [LengthLimitingTextInputFormatter(maxLenght)],
decoration: InputDecoration(
counterText: '${controller.text.length}/$maxLenght',
hintText: AppLocalizations.of(context)!
.technical_issue_text_field_placeholder),
minLines: 10,
maxLines: 35,
);
}
}
class _PolicyTextButtons extends StatelessWidget {
const _PolicyTextButtons();
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
onPressed: () => context.pushNamed(webViewRouteName,
extra: WebViewExtra(
title: AppLocalizations.of(context)!.user_agreement_link_text,
url:
"https://help.keen.com/hc/en-us/articles/360060613533-Feedback-Policy",
)),
child: Text(AppLocalizations.of(context)!.feedback_policy),
),
const SizedBox(width: 5),
CircleAvatar(
backgroundColor: context.keenColors.primary.withOpacity(.7),
maxRadius: 2,
),
const SizedBox(width: 5),
TextButton(
onPressed: () => context.pushNamed(webViewRouteName,
extra: WebViewExtra(
title: AppLocalizations.of(context)!.user_agreement_link_text,
url: GetIt.instance<AppConfig>()
.localizedLinks
.userAgreement
.replaceAll('%s', 'en-us'),
)),
child: Text(AppLocalizations.of(context)!.user_agreement_link_text),
)
],
);
}
}