2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/constants.dart';
|
|
|
|
|
import 'package:fcs/domain/entities/faq.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/localization/app_translations.dart';
|
|
|
|
|
import 'package:fcs/pages/faq/model/faq_model.dart';
|
|
|
|
|
import 'package:fcs/pages/faq/widgets.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/input_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-09-07 16:05:28 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_icons/flutter_icons.dart';
|
2020-09-11 16:14:36 +06:30
|
|
|
import 'package:provider/provider.dart';
|
2020-09-07 16:05:28 +06:30
|
|
|
|
2020-09-18 21:33:41 +06:30
|
|
|
const info = "Select additional page";
|
|
|
|
|
|
2020-09-07 16:05:28 +06:30
|
|
|
class FAQEditor extends StatefulWidget {
|
|
|
|
|
final FAQ faq;
|
|
|
|
|
const FAQEditor({this.faq});
|
|
|
|
|
@override
|
|
|
|
|
_FAQEditorState createState() => _FAQEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _FAQEditorState extends State<FAQEditor> {
|
2020-09-11 16:14:36 +06:30
|
|
|
TextEditingController _sn = new TextEditingController();
|
2020-09-07 16:05:28 +06:30
|
|
|
TextEditingController _engQ = new TextEditingController();
|
|
|
|
|
TextEditingController _mmQ = new TextEditingController();
|
|
|
|
|
TextEditingController _engA = new TextEditingController();
|
|
|
|
|
TextEditingController _mmA = new TextEditingController();
|
2020-09-18 21:33:41 +06:30
|
|
|
TextEditingController _pageLabelEng = new TextEditingController();
|
|
|
|
|
TextEditingController _pageLabelMm = new TextEditingController();
|
2020-09-07 16:05:28 +06:30
|
|
|
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
bool _isNew = false;
|
2020-09-18 21:33:41 +06:30
|
|
|
String _pageLink = info;
|
|
|
|
|
|
2020-09-07 16:05:28 +06:30
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_isNew = widget.faq == null;
|
|
|
|
|
if (widget.faq != null) {
|
2020-09-11 16:14:36 +06:30
|
|
|
_sn.text = widget.faq.sn.toString();
|
2020-09-07 16:05:28 +06:30
|
|
|
_engQ.text = widget.faq.questionEng;
|
|
|
|
|
_mmQ.text = widget.faq.questionMm;
|
|
|
|
|
_engA.text = widget.faq.answerEng;
|
|
|
|
|
_mmA.text = widget.faq.answerMm;
|
2020-09-18 21:33:41 +06:30
|
|
|
_pageLabelEng.text = widget.faq.pageLinkLabelEng;
|
|
|
|
|
_pageLabelMm.text = widget.faq.pageLinkLabelMm;
|
|
|
|
|
_pageLink = widget.faq.pageLink;
|
2020-09-07 16:05:28 +06:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-11 16:14:36 +06:30
|
|
|
final snBox = InputText(
|
|
|
|
|
controller: _sn,
|
2020-09-15 07:13:41 +06:30
|
|
|
labelTextKey: "faq.edit.sn",
|
2020-09-11 16:14:36 +06:30
|
|
|
maxLines: 1,
|
2020-09-15 07:13:41 +06:30
|
|
|
withBorder: false,
|
2020-09-11 16:14:36 +06:30
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final questionEngBox = InputText(
|
2020-09-07 16:05:28 +06:30
|
|
|
controller: _engQ,
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
withBorder: true,
|
|
|
|
|
);
|
2020-09-11 16:14:36 +06:30
|
|
|
final answerEngBox = InputText(
|
|
|
|
|
controller: _engA,
|
2020-09-07 16:05:28 +06:30
|
|
|
maxLines: 5,
|
|
|
|
|
withBorder: true,
|
|
|
|
|
);
|
2020-09-11 16:14:36 +06:30
|
|
|
final questionMmBox = InputText(
|
|
|
|
|
controller: _mmQ,
|
2020-09-07 16:05:28 +06:30
|
|
|
maxLines: 2,
|
|
|
|
|
withBorder: true,
|
|
|
|
|
);
|
2020-09-11 16:14:36 +06:30
|
|
|
final answerMmBox = InputText(
|
2020-09-07 16:05:28 +06:30
|
|
|
controller: _mmA,
|
|
|
|
|
maxLines: 5,
|
|
|
|
|
withBorder: true,
|
|
|
|
|
);
|
2020-09-18 21:33:41 +06:30
|
|
|
final pageLinkBox = DropdownButton<String>(
|
|
|
|
|
value: _pageLink,
|
|
|
|
|
style: TextStyle(color: Colors.deepPurple),
|
|
|
|
|
underline: Container(
|
|
|
|
|
height: 2,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
onChanged: (String newValue) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_pageLink = newValue;
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-10-15 03:06:13 +06:30
|
|
|
items: <String>[
|
|
|
|
|
info,
|
|
|
|
|
page_buying_instructions,
|
|
|
|
|
page_payment_methods,
|
|
|
|
|
page_rates
|
|
|
|
|
].map<DropdownMenuItem<String>>((String value) {
|
2020-09-18 21:33:41 +06:30
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
|
value: value,
|
|
|
|
|
child: Text(
|
|
|
|
|
value,
|
|
|
|
|
style:
|
|
|
|
|
TextStyle(color: value == info ? Colors.black : primaryColor),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
);
|
|
|
|
|
final pageLabelEngBox = InputText(
|
|
|
|
|
controller: _pageLabelEng,
|
|
|
|
|
labelTextKey: "faq.edit.page.label.eng",
|
|
|
|
|
);
|
|
|
|
|
final pageLabelMmBox = InputText(
|
|
|
|
|
controller: _pageLabelMm,
|
|
|
|
|
labelTextKey: "faq.edit.page.label.mm",
|
|
|
|
|
);
|
2020-09-07 16:05:28 +06:30
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
2020-10-15 03:06:13 +06:30
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
|
|
|
|
icon: new Icon(CupertinoIcons.back, color: primaryColor),
|
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context, _isNew ? 'faq.add.title' : 'faq.edit.title',
|
|
|
|
|
color: primaryColor, fontSize: 20),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
2020-10-17 01:40:24 +06:30
|
|
|
icon: Icon(
|
|
|
|
|
Icons.delete,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
2020-10-15 03:06:13 +06:30
|
|
|
onPressed: _delete,
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
snBox,
|
|
|
|
|
Center(child: itemTitle(context, "faq.edit.eng")),
|
|
|
|
|
subItemTitle(context, "faq.edit.question",
|
|
|
|
|
iconData: SimpleLineIcons.question),
|
|
|
|
|
questionEngBox,
|
|
|
|
|
subItemTitle(context, "faq.edit.answer",
|
|
|
|
|
iconData: MaterialCommunityIcons.message_reply_text),
|
|
|
|
|
answerEngBox,
|
|
|
|
|
Divider(),
|
|
|
|
|
Center(child: itemTitle(context, "faq.edit.mm")),
|
|
|
|
|
subItemTitle(context, "faq.edit.question",
|
|
|
|
|
iconData: SimpleLineIcons.question),
|
|
|
|
|
questionMmBox,
|
|
|
|
|
subItemTitle(context, "faq.edit.answer",
|
|
|
|
|
iconData: MaterialCommunityIcons.message_reply_text),
|
|
|
|
|
answerMmBox,
|
|
|
|
|
Divider(),
|
|
|
|
|
Center(child: itemTitle(context, "faq.edit.page")),
|
|
|
|
|
pageLinkBox,
|
|
|
|
|
pageLabelEngBox,
|
|
|
|
|
pageLabelMmBox,
|
|
|
|
|
fcsButton(context, getLocalString(context, "btn.save"),
|
|
|
|
|
callack: _save),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)));
|
2020-09-07 16:05:28 +06:30
|
|
|
}
|
|
|
|
|
|
2020-09-11 16:14:36 +06:30
|
|
|
_save() async {
|
2020-09-07 16:05:28 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
2020-09-11 16:14:36 +06:30
|
|
|
int sn = int.parse(
|
|
|
|
|
_sn.text,
|
|
|
|
|
onError: (source) => throw Exception("Invalid number"),
|
|
|
|
|
);
|
|
|
|
|
FAQModel faqModel = Provider.of<FAQModel>(context, listen: false);
|
|
|
|
|
FAQ _faq = FAQ(
|
|
|
|
|
sn: sn,
|
|
|
|
|
questionEng: _engQ.text,
|
|
|
|
|
answerEng: _engA.text,
|
|
|
|
|
questionMm: _mmQ.text,
|
2020-09-18 21:33:41 +06:30
|
|
|
answerMm: _mmA.text,
|
|
|
|
|
pageLinkLabelEng: _pageLabelEng.text,
|
|
|
|
|
pageLinkLabelMm: _pageLabelMm.text,
|
|
|
|
|
pageLink: _pageLink);
|
2020-09-11 16:14:36 +06:30
|
|
|
if (_isNew) {
|
|
|
|
|
await faqModel.addFAQ(_faq);
|
|
|
|
|
} else {
|
|
|
|
|
_faq.id = widget.faq.id;
|
|
|
|
|
await faqModel.updateFAQ(_faq);
|
|
|
|
|
}
|
2020-09-07 16:05:28 +06:30
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-18 21:33:41 +06:30
|
|
|
|
|
|
|
|
_delete() {
|
|
|
|
|
showConfirmDialog(context, "faq.edit.delete.confirm", _deleteFAQ);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_deleteFAQ() async {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
FAQModel faqModel = Provider.of<FAQModel>(context, listen: false);
|
|
|
|
|
await faqModel.deleteFAQ(widget.faq);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-07 16:05:28 +06:30
|
|
|
}
|