dev
dart 65 lines 1.72 KB
Raw
1 import 'package:flutter/material.dart';
2
3 class FAQItem extends StatefulWidget {
4 FAQItem(this.title, this.text);
5
6 final String title;
7 final String text;
8
9 @override
10 State<StatefulWidget> createState() => FAQItemState();
11 }
12
13 class FAQItemState extends State<FAQItem> {
14 FAQItemState() : isActive = false;
15
16 bool isActive;
17
18 @override
19 void initState() {
20 isActive = false;
21 super.initState();
22 }
23
24 @override
25 Widget build(BuildContext context) {
26 final addIcon = Icon(Icons.add, color: Theme.of(context).colorScheme.onSurface);
27 final removeIcon = Icon(Icons.remove, color: Theme.of(context).colorScheme.primary);
28 final icon = isActive ? removeIcon : addIcon;
29 final color =
30 isActive ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onSurface;
31
32 return ListTileTheme(
33 contentPadding: EdgeInsets.fromLTRB(0, 6, 24, 6),
34 child: ExpansionTile(
35 title: Text(
36 widget.title,
37 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
38 fontWeight: FontWeight.w500,
39 color: color,
40 ),
41 ),
42 trailing: icon,
43 onExpansionChanged: (value) => setState(() => isActive = value),
44 children: <Widget>[
45 Row(
46 mainAxisAlignment: MainAxisAlignment.start,
47 children: <Widget>[
48 Expanded(
49 child: Container(
50 padding: EdgeInsets.only(
51 right: 24.0,
52 ),
53 child: Text(
54 widget.text,
55 style: Theme.of(context).textTheme.bodyMedium,
56 ),
57 ),
58 )
59 ],
60 ),
61 ],
62 ),
63 );
64 }
65 }