-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathkeep_state_page.dart
More file actions
118 lines (113 loc) · 3.7 KB
/
Copy pathkeep_state_page.dart
File metadata and controls
118 lines (113 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import 'package:expansion_tile_group/expansion_tile_group.dart';
import 'package:flutter/material.dart';
class KeepStatePage extends StatefulWidget {
const KeepStatePage({super.key});
@override
State<KeepStatePage> createState() => _KeepStatePageState();
}
class _KeepStatePageState extends State<KeepStatePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Keep State Example'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Row(
children: [
_buildGroupLayout(
context,
title: 'Group 1: keepState: true',
child: ExpansionTileGroup(
spaceBetweenItem: 16,
keepState: true,
children: [
_buildExpansionItem(context),
_buildExpansionItem(context),
_buildExpansionItem(context),
],
),
),
const SizedBox(
width: 16,
),
_buildGroupLayout(
context,
title: 'Group 2: keepState: false',
child: ExpansionTileGroup(
spaceBetweenItem: 16,
keepState: false,
children: [
_buildExpansionItem(context),
_buildExpansionItem(context),
_buildExpansionItem(context),
],
),
),
],
),
const SizedBox(
height: 16,
),
const Text(
'Try to expand some items of each group and then tap to below button, you can see the different',
textAlign: TextAlign.center,
),
const SizedBox(
height: 16,
),
ElevatedButton(
onPressed: () {
setState(() {});
},
child: const Text('Rebuild this Page')),
],
),
),
),
);
}
ExpansionTileItem _buildExpansionItem(BuildContext context,
{bool isExpanded = false}) {
return ExpansionTileItem.outlined(
initiallyExpanded: isExpanded,
title: const Text('ExpansionTile Item'),
children: [
Material(
child: InkWell(
onTap: () {},
child: const Text(
''' Nullam eleifend ultrices tortor, sit amet gravida sapien cursus vitae. Duis rutrum convallis erat et ultrices. Morbi a luctus ligula, at varius ligula. Nam mollis sapien ac nunc hendrerit consequat. Cras posuere metus felis, at pellentesque sem ornare id. Praesent ut nunc aliquam, dictum felis eu, congue metus. Nunc vitae elit eros. In eu dui pharetra, varius metus a, efficitur eros.'''),
),
),
],
);
}
Widget _buildGroupLayout(BuildContext context,
{required String title, required Widget child}) {
return Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(fontSize: 20),
),
const SizedBox(
height: 16,
),
Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: child,
),
),
],
),
);
}
}