2020-09-07 16:05:28 +06:30
|
|
|
import 'package:fcs/fcs/common/domain/entities/faq.dart';
|
|
|
|
|
import 'package:fcs/fcs/common/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/fcs/common/localization/app_translations.dart';
|
2020-09-11 16:14:36 +06:30
|
|
|
import 'package:fcs/fcs/common/pages/faq/model/faq_model.dart';
|
2020-09-10 16:04:09 +06:30
|
|
|
import 'package:fcs/fcs/common/pages/faq/widgets.dart';
|
2020-09-07 16:05:28 +06:30
|
|
|
import 'package:fcs/fcs/common/pages/util.dart';
|
|
|
|
|
import 'package:fcs/fcs/common/pages/widgets/input_text.dart';
|
|
|
|
|
import 'package:fcs/fcs/common/pages/widgets/progress.dart';
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
bool _isNew = false;
|
|
|
|
|
@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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-11 16:14:36 +06:30
|
|
|
final snBox = InputText(
|
|
|
|
|
controller: _sn,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
withBorder: true,
|
|
|
|
|
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,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
2020-09-11 16:14:36 +06:30
|
|
|
child: Scaffold(
|
|
|
|
|
body: CustomScrollView(slivers: [
|
|
|
|
|
SliverAppBar(
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
CupertinoIcons.back,
|
|
|
|
|
size: 30,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
expandedHeight: 150.0,
|
|
|
|
|
floating: true,
|
|
|
|
|
pinned: true,
|
|
|
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
titlePadding: EdgeInsets.symmetric(vertical: 10),
|
|
|
|
|
title: Text(
|
|
|
|
|
AppTranslations.of(context)
|
|
|
|
|
.text(_isNew ? 'faq.add.title' : 'faq.edit.title'),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () => _save(),
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.save,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SliverList(
|
|
|
|
|
delegate: SliverChildListDelegate([
|
|
|
|
|
Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 18.0, left: 0),
|
|
|
|
|
child: subItemTitle(context, "faq.edit.sn"),
|
2020-09-07 16:05:28 +06:30
|
|
|
),
|
2020-09-11 16:14:36 +06:30
|
|
|
Expanded(child: snBox),
|
2020-09-07 16:05:28 +06:30
|
|
|
],
|
|
|
|
|
),
|
2020-09-11 16:14:36 +06:30
|
|
|
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,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
]))
|
|
|
|
|
])));
|
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,
|
|
|
|
|
answerMm: _mmA.text);
|
|
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|