|
1 | | -import 'package:flutter/cupertino.dart'; |
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:pslab/colors.dart'; |
| 3 | +import 'package:pslab/view/widgets/main_scaffold_widget.dart'; |
| 4 | +import 'package:url_launcher/url_launcher.dart'; |
| 5 | +import 'package:pslab/constants.dart'; |
2 | 6 |
|
3 | 7 | class FAQScreen extends StatelessWidget { |
| 8 | + static const List<FAQItem> faqs = [ |
| 9 | + FAQItem( |
| 10 | + question: FAQConstants.whatIsPslab, |
| 11 | + answer: FAQConstants.whatIsPslabAnswer, |
| 12 | + ), |
| 13 | + FAQItem( |
| 14 | + question: FAQConstants.whereToBuy, |
| 15 | + answer: FAQConstants.whereToBuyAnswer, |
| 16 | + linkText: FAQConstants.whereToBuyLinkText, |
| 17 | + linkUrl: FAQConstants.whereToBuyLinkUrl, |
| 18 | + ), |
| 19 | + FAQItem( |
| 20 | + question: FAQConstants.downloadAndroidApp, |
| 21 | + answer: FAQConstants.downloadAndroidAppAnswer, |
| 22 | + linkText: FAQConstants.downloadAndroidAppLinkText, |
| 23 | + linkUrl: FAQConstants.downloadAndroidAppLinkUrl, |
| 24 | + ), |
| 25 | + FAQItem( |
| 26 | + question: FAQConstants.downloadDesktopApp, |
| 27 | + answer: FAQConstants.downloadDesktopAppAnswer, |
| 28 | + ), |
| 29 | + FAQItem( |
| 30 | + question: FAQConstants.howToConnect, |
| 31 | + answer: FAQConstants.howToConnectAnswer, |
| 32 | + ), |
| 33 | + FAQItem( |
| 34 | + question: FAQConstants.reportBug, |
| 35 | + answer: FAQConstants.reportBugAnswer, |
| 36 | + linkText: FAQConstants.reportBugLinkText, |
| 37 | + linkUrl: FAQConstants.reportBugLinkUrl), |
| 38 | + FAQItem( |
| 39 | + question: FAQConstants.recordData, |
| 40 | + answer: FAQConstants.recordDataAnswer, |
| 41 | + ), |
| 42 | + FAQItem( |
| 43 | + question: FAQConstants.usePhoneSensors, |
| 44 | + answer: FAQConstants.usePhoneSensorsAnswer, |
| 45 | + ), |
| 46 | + FAQItem( |
| 47 | + question: FAQConstants.compatibleSensors, |
| 48 | + answer: FAQConstants.compatibleSensorsAnswer, |
| 49 | + ), |
| 50 | + ]; |
| 51 | + |
4 | 52 | const FAQScreen({super.key}); |
5 | 53 |
|
6 | 54 | @override |
7 | 55 | Widget build(BuildContext context) { |
8 | | - // TODO: implement build |
9 | | - throw UnimplementedError(); |
| 56 | + return MainScaffold( |
| 57 | + title: faqTitle, |
| 58 | + index: 6, |
| 59 | + body: ListView.separated( |
| 60 | + padding: const EdgeInsets.symmetric(vertical: 8), |
| 61 | + itemCount: faqs.length, |
| 62 | + separatorBuilder: (context, index) => const Divider(height: 1), |
| 63 | + itemBuilder: (context, index) => _buildFAQItem(faqs[index]), |
| 64 | + ), |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + Widget _buildFAQItem(FAQItem faq) { |
| 69 | + return Padding( |
| 70 | + padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), |
| 71 | + child: ExpansionTile( |
| 72 | + tilePadding: EdgeInsets.zero, |
| 73 | + shape: const Border(), |
| 74 | + collapsedShape: const Border(), |
| 75 | + title: Padding( |
| 76 | + padding: const EdgeInsets.only(bottom: 0), |
| 77 | + child: Row(children: [ |
| 78 | + Text( |
| 79 | + Q, |
| 80 | + style: TextStyle( |
| 81 | + color: primaryRed, |
| 82 | + ), |
| 83 | + ), |
| 84 | + const SizedBox( |
| 85 | + width: 10, |
| 86 | + ), |
| 87 | + Flexible( |
| 88 | + child: Text( |
| 89 | + faq.question, |
| 90 | + style: TextStyle( |
| 91 | + color: primaryRed, |
| 92 | + ), |
| 93 | + ), |
| 94 | + ), |
| 95 | + ]), |
| 96 | + ), |
| 97 | + childrenPadding: const EdgeInsets.fromLTRB(5, 0, 16, 16), |
| 98 | + expandedCrossAxisAlignment: CrossAxisAlignment.start, |
| 99 | + trailing: const SizedBox(), |
| 100 | + children: [ |
| 101 | + Padding( |
| 102 | + padding: const EdgeInsets.only(top: 0), |
| 103 | + child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [ |
| 104 | + Text( |
| 105 | + A, |
| 106 | + style: const TextStyle( |
| 107 | + color: Colors.black, |
| 108 | + ), |
| 109 | + ), |
| 110 | + const SizedBox( |
| 111 | + width: 10, |
| 112 | + ), |
| 113 | + Flexible( |
| 114 | + child: Text( |
| 115 | + faq.answer, |
| 116 | + style: const TextStyle( |
| 117 | + color: Colors.black, |
| 118 | + ), |
| 119 | + ), |
| 120 | + ), |
| 121 | + ]), |
| 122 | + ), |
| 123 | + if (faq.linkText != null && faq.linkUrl != null) |
| 124 | + Padding( |
| 125 | + padding: const EdgeInsets.only(top: 8), |
| 126 | + child: GestureDetector( |
| 127 | + onTap: () => _launchURL(faq.linkUrl!), |
| 128 | + child: Row( |
| 129 | + children: [ |
| 130 | + const SizedBox( |
| 131 | + width: 25, |
| 132 | + ), |
| 133 | + Text( |
| 134 | + faq.linkText!, |
| 135 | + style: TextStyle( |
| 136 | + color: primaryRed, |
| 137 | + decoration: TextDecoration.underline, |
| 138 | + ), |
| 139 | + ), |
| 140 | + ], |
| 141 | + ), |
| 142 | + ), |
| 143 | + ), |
| 144 | + ], |
| 145 | + ), |
| 146 | + ); |
| 147 | + } |
| 148 | + |
| 149 | + Future<void> _launchURL(String url) async { |
| 150 | + final Uri uri = Uri.parse(url); |
| 151 | + if (await canLaunchUrl(uri)) { |
| 152 | + await launchUrl(uri); |
| 153 | + } else { |
| 154 | + throw '$launchError $url'; |
| 155 | + } |
10 | 156 | } |
11 | 157 | } |
| 158 | + |
| 159 | +class FAQItem { |
| 160 | + final String question; |
| 161 | + final String answer; |
| 162 | + final String? linkText; |
| 163 | + final String? linkUrl; |
| 164 | + |
| 165 | + const FAQItem({ |
| 166 | + required this.question, |
| 167 | + required this.answer, |
| 168 | + this.linkText, |
| 169 | + this.linkUrl, |
| 170 | + }); |
| 171 | +} |
0 commit comments