Files
fcs/lib/pages/faq/faq_list_page.dart

145 lines
4.6 KiB
Dart
Raw Normal View History

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/pages/buying_instruction/buying_online.dart';
import 'package:fcs/pages/faq/faq_edit_page.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/payment_methods/payment_method_page.dart';
2020-10-15 03:06:13 +06:30
import 'package:fcs/pages/rates/shipment_rates.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/fcs_expansion_tile.dart';
2024-01-25 17:40:35 +06:30
import 'package:fcs/pages/widgets/local_app_bar.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
2020-09-07 16:05:28 +06:30
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
2020-09-11 16:14:36 +06:30
import 'model/faq_model.dart';
2020-09-07 16:05:28 +06:30
2020-09-13 21:49:39 +06:30
class FAQListPage extends StatefulWidget {
2020-09-07 16:05:28 +06:30
@override
2020-09-13 21:49:39 +06:30
_FAQListPageState createState() => _FAQListPageState();
2020-09-07 16:05:28 +06:30
}
2020-09-15 07:13:41 +06:30
class _FAQListPageState extends State<FAQListPage>
with SingleTickerProviderStateMixin {
2020-09-07 16:05:28 +06:30
@override
Widget build(BuildContext context) {
2020-09-11 16:14:36 +06:30
FAQModel faqModel = Provider.of<FAQModel>(context);
bool isEditable = context.select((MainModel m) => m.faqEditable());
2020-09-10 16:04:09 +06:30
return Scaffold(
2024-01-25 17:40:35 +06:30
appBar: LocalAppBar(
labelKey: "faq.title",
2020-10-15 03:06:13 +06:30
actions: isEditable
? [
IconButton(
onPressed: () => setState(() {
isEditMode = !isEditMode;
}),
icon: Icon(
Icons.edit,
color: Colors.white,
))
]
: [],
),
2020-09-15 07:13:41 +06:30
floatingActionButton: isEditable
? FloatingActionButton.extended(
onPressed: () {
2020-10-14 13:54:42 +06:30
Navigator.of(context).push(
CupertinoPageRoute(builder: (context) => FAQEditor()));
2020-09-15 07:13:41 +06:30
},
icon: Icon(Icons.add),
label: LocalText(context, "faq.add.title", color: Colors.white),
backgroundColor: primaryColor,
)
: Container(),
2020-10-15 03:06:13 +06:30
body: ListView.builder(
itemCount: faqModel.faqs.length,
itemBuilder: (BuildContext context, int index) {
return _faqItem(context, faqModel.faqs[index]);
}));
2020-09-10 16:04:09 +06:30
}
2020-09-15 07:13:41 +06:30
bool isEditMode = false;
2020-09-07 16:05:28 +06:30
Widget _faqItem(BuildContext context, FAQ faq) {
bool isEng = Provider.of<LanguageModel>(context).isEng;
2020-09-15 07:13:41 +06:30
2020-09-10 16:04:09 +06:30
return Column(
children: [
2020-09-15 07:13:41 +06:30
Padding(
padding: const EdgeInsets.all(8.0),
child: FcsExpansionTile(
isEdit: isEditMode,
title: TextLocalStyle(
context,
faq.question(isEng),
fontSize: 16,
2020-09-18 21:33:41 +06:30
fontWeight: FontWeight.w600,
color: primaryColor,
2020-09-15 07:13:41 +06:30
),
onEditPress: () {
Navigator.of(context).push<void>(CupertinoPageRoute(
builder: (context) => FAQEditor(faq: faq),
));
},
children: [getAnwser(context, faq)],
),
),
Divider(
thickness: 2,
2020-09-10 16:04:09 +06:30
),
],
2020-09-07 16:05:28 +06:30
);
}
2020-09-15 07:13:41 +06:30
Widget getAnwser(BuildContext context, FAQ faq) {
bool isEng = Provider.of<LanguageModel>(context).isEng;
2020-09-18 21:33:41 +06:30
return Column(
children: [
TextLocalStyle(
context,
faq.answer(isEng),
fontSize: 16,
2020-10-19 17:09:24 +06:30
fontWeight: FontWeight.w400,
2020-09-18 21:33:41 +06:30
),
_pageLink(
faq.pageLink,
isEng ? faq.pageLinkLabelEng : faq.pageLinkLabelMm,
),
],
2020-09-15 07:13:41 +06:30
);
}
2020-09-18 21:33:41 +06:30
2021-09-10 12:02:08 +06:30
Widget _pageLink(String? linkPage, String? text) {
2020-09-18 21:33:41 +06:30
return linkPage == null || linkPage == "" || text == null || text == ""
? Container()
: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
2024-01-09 13:11:22 +06:30
TextButton(
style: TextButton.styleFrom(backgroundColor: primaryColor),
// color: primaryColor,
2020-09-18 21:33:41 +06:30
onPressed: () => _selectLinkPage(linkPage),
child: LocalText(context, "", text: text, color: Colors.white),
)
],
);
}
_selectLinkPage(String linkPage) {
if (linkPage == page_payment_methods) {
2020-10-14 13:54:42 +06:30
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => PaymentMethodPage()));
2020-09-18 21:33:41 +06:30
} else if (linkPage == page_buying_instructions) {
2020-10-14 13:54:42 +06:30
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => BuyingOnlinePage()));
2020-10-15 03:06:13 +06:30
} else if (linkPage == page_rates) {
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => ShipmentRates()));
2020-09-18 21:33:41 +06:30
}
}
2020-09-07 16:05:28 +06:30
}