Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
1e50518c
Unverified
Commit
1e50518c
authored
Apr 04, 2019
by
Shi-Hao Hong
Committed by
GitHub
Apr 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ExpansionPanelList and ExpansionPanelList.radio Examples (#30343)
parent
eb4b3e4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
0 deletions
+151
-0
expansion_panel.dart
packages/flutter/lib/src/material/expansion_panel.dart
+151
-0
No files found.
packages/flutter/lib/src/material/expansion_panel.dart
View file @
1e50518c
...
@@ -56,12 +56,15 @@ typedef ExpansionPanelHeaderBuilder = Widget Function(BuildContext context, bool
...
@@ -56,12 +56,15 @@ typedef ExpansionPanelHeaderBuilder = Widget Function(BuildContext context, bool
/// Expansion panels are only intended to be used as children for
/// Expansion panels are only intended to be used as children for
/// [ExpansionPanelList].
/// [ExpansionPanelList].
///
///
/// See [ExpansionPanelList] for a sample implementation.
///
/// See also:
/// See also:
///
///
/// * [ExpansionPanelList]
/// * [ExpansionPanelList]
/// * <https://material.io/design/components/lists.html#types>
/// * <https://material.io/design/components/lists.html#types>
class
ExpansionPanel
{
class
ExpansionPanel
{
/// Creates an expansion panel to be used as a child for [ExpansionPanelList].
/// Creates an expansion panel to be used as a child for [ExpansionPanelList].
/// See [ExpansionPanelList] for an example on how to use this widget.
///
///
/// The [headerBuilder], [body], and [isExpanded] arguments must not be null.
/// The [headerBuilder], [body], and [isExpanded] arguments must not be null.
ExpansionPanel
({
ExpansionPanel
({
...
@@ -88,8 +91,14 @@ class ExpansionPanel {
...
@@ -88,8 +91,14 @@ class ExpansionPanel {
}
}
/// An expansion panel that allows for radio-like functionality.
/// An expansion panel that allows for radio-like functionality.
/// This means that at any given time, at most, one [ExpansionPanelRadio]
/// can remain expanded.
///
///
/// A unique identifier [value] must be assigned to each panel.
/// A unique identifier [value] must be assigned to each panel.
/// This identifier allows the [ExpansionPanelList] to determine
/// which [ExpansionPanelRadio] instance should be expanded.
///
/// See [ExpansionPanelList.radio] for a sample implementation.
class
ExpansionPanelRadio
extends
ExpansionPanel
{
class
ExpansionPanelRadio
extends
ExpansionPanel
{
/// An expansion panel that allows for radio functionality.
/// An expansion panel that allows for radio functionality.
...
@@ -111,9 +120,82 @@ class ExpansionPanelRadio extends ExpansionPanel {
...
@@ -111,9 +120,82 @@ class ExpansionPanelRadio extends ExpansionPanel {
/// A material expansion panel list that lays out its children and animates
/// A material expansion panel list that lays out its children and animates
/// expansions.
/// expansions.
///
///
/// {@tool snippet --template=stateful_widget_material}
///
/// Here is a simple example of how to implement ExpansionPanelList.
///
/// ```dart preamble
/// // stores ExpansionPanel state information
/// class Item {
/// Item({
/// this.expandedValue,
/// this.headerValue,
/// this.isExpanded = false,
/// });
///
/// String expandedValue;
/// String headerValue;
/// bool isExpanded;
/// }
///
/// List<Item> generateItems(int numberOfItems) {
/// return List.generate(numberOfItems, (int index) {
/// return Item(
/// headerValue: 'Panel $index',
/// expandedValue: 'This is item number $index',
/// );
/// });
/// }
/// ```
///
/// ```dart
/// List<Item> _data = generateItems(8);
///
/// @override
/// Widget build(BuildContext context) {
/// return SingleChildScrollView(
/// child: Container(
/// child: _buildPanel(),
/// ),
/// );
/// }
///
/// Widget _buildPanel() {
/// return ExpansionPanelList(
/// expansionCallback: (int index, bool isExpanded) {
/// setState(() {
/// _data[index].isExpanded = !isExpanded;
/// });
/// },
/// children: _data.map<ExpansionPanel>((Item item) {
/// return ExpansionPanel(
/// headerBuilder: (BuildContext context, bool isExpanded) {
/// return ListTile(
/// title: Text(item.headerValue),
/// );
/// },
/// body: ListTile(
/// title: Text(item.expandedValue),
/// subtitle: Text('To delete this panel, tap the trash can icon'),
/// trailing: Icon(Icons.delete),
/// onTap: () {
/// setState(() {
/// _data.removeWhere((currentItem) => item == currentItem);
/// });
/// }
/// ),
/// isExpanded: item.isExpanded,
/// );
/// }).toList(),
/// );
/// }
/// ```
/// {@end-tool}
///
/// See also:
/// See also:
///
///
/// * [ExpansionPanel]
/// * [ExpansionPanel]
/// * [ExpansionPanelList.radio]
/// * <https://material.io/design/components/lists.html#types>
/// * <https://material.io/design/components/lists.html#types>
class
ExpansionPanelList
extends
StatefulWidget
{
class
ExpansionPanelList
extends
StatefulWidget
{
/// Creates an expansion panel list widget. The [expansionCallback] is
/// Creates an expansion panel list widget. The [expansionCallback] is
...
@@ -138,6 +220,75 @@ class ExpansionPanelList extends StatefulWidget {
...
@@ -138,6 +220,75 @@ class ExpansionPanelList extends StatefulWidget {
/// expand/collapse button is pushed. The [children] and [animationDuration]
/// expand/collapse button is pushed. The [children] and [animationDuration]
/// arguments must not be null. The [children] objects must be instances
/// arguments must not be null. The [children] objects must be instances
/// of [ExpansionPanelRadio].
/// of [ExpansionPanelRadio].
///
/// {@tool snippet --template=stateful_widget_material}
///
/// Here is a simple example of how to implement ExpansionPanelList.radio.
///
/// ```dart preamble
/// // stores ExpansionPanel state information
/// class Item {
/// Item({
/// this.id,
/// this.expandedValue,
/// this.headerValue,
/// });
///
/// int id;
/// String expandedValue;
/// String headerValue;
/// }
///
/// List<Item> generateItems(int numberOfItems) {
/// return List.generate(numberOfItems, (int index) {
/// return Item(
/// id: index,
/// headerValue: 'Panel $index',
/// expandedValue: 'This is item number $index',
/// );
/// });
/// }
/// ```
///
/// ```dart
/// List<Item> _data = generateItems(8);
///
/// @override
/// Widget build(BuildContext context) {
/// return SingleChildScrollView(
/// child: Container(
/// child: _buildPanel(),
/// ),
/// );
/// }
///
/// Widget _buildPanel() {
/// return ExpansionPanelList.radio(
/// initialOpenPanelValue: 2,
/// children: _data.map<ExpansionPanelRadio>((Item item) {
/// return ExpansionPanelRadio(
/// value: item.id,
/// headerBuilder: (BuildContext context, bool isExpanded) {
/// return ListTile(
/// title: Text(item.headerValue),
/// );
/// },
/// body: ListTile(
/// title: Text(item.expandedValue),
/// subtitle: Text('To delete this panel, tap the trash can icon'),
/// trailing: Icon(Icons.delete),
/// onTap: () {
/// setState(() {
/// _data.removeWhere((currentItem) => item == currentItem);
/// });
/// }
/// )
/// );
/// }).toList(),
/// );
/// }
/// ```
/// {@end-tool}
const
ExpansionPanelList
.
radio
({
const
ExpansionPanelList
.
radio
({
Key
key
,
Key
key
,
this
.
children
=
const
<
ExpansionPanelRadio
>[],
this
.
children
=
const
<
ExpansionPanelRadio
>[],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment