当前位置:网站首页>The fluent application creates a list of expansion panels
The fluent application creates a list of expansion panels
2022-04-22 11:47:00 【A cat that can make coffee】

original text
https://medium.flutterdevs.com/expansionpanellist-in-flutter-48aa06f764e
Reference resources
- https://api.flutter.dev/flutter/material/ExpansionPanelList-class.html
Text
Learn how to Flutter The application creates a list of extension panels

In this paper , We'll talk about ExpansionPanelList In Flutter. . We will implement an extension panel list Demo , And learn how to customize its style with different attributes in your Flutter Applications .
Expansion Panel List:
It is a similar to listView Materiality of Flutter The widget . It can only have an expansion panel as a child . In some cases , We may need to display a list , The child elements can be expanded / Collapse to show / Hide some detailed data . To display such a list flutter, A file named ExapansionPanelList The widget of .
In this list , Every subelement is expsionpanel The widget . In this list , We can't use different widgets as child windows . We can use expsioncallback Property to handle the state adjustment of things ( Expand or crash ).
Demo module :

This demo video shows how to work in a Flutter Expansion panel list . It shows how the extension panel list will work in your Flutter Applications . It shows a list , In this list, children can expand / Collapse to show / Hide some details . It will show up on your device .
Constructor:
To use ExpansionPanelList, You need to call the following constructor :
const ExpansionPanelList({
Key? key,
this.children = const <ExpansionPanel>[],
this.expansionCallback,
this.animationDuration = kThemeAnimationDuration,
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
this.dividerColor,
this.elevation = 2,
})
Properties:
ExpansionPanelList Some properties of are as follows :
- > children: This property is used for expansion panels List Child elements . Their layout is similar to [ListBody].
- > expansionCallback: This property is used whenever an expansion is pressed / Callback called when the button is collapsed . The parameter passed to the callback is the index of the panel pressed , And whether the panel is currently expanded .
- > animationDuration: This property is used when expanding or collapsing , We can observe that some animations occur within a certain period of time . We can use the expansion panel List Of animationDuration Property to change the duration . We just need to provide in microseconds 、 Duration value in milliseconds or minutes .
- > expandedHeaderPadding: This property is used for padding around the panel header when expanding . By default ,16px The space is added vertically to the title during expansion ( Above and below ).
- > dividerColor: When [ expsionpanel.isexpanded ] by false when , This property defines the color of the separator . If ‘ dividerColor’ It's empty , Then use [ DividerThemeData.color ]. If null, Then use [ ThemeData.dividerColor ].
- > elevation: This property is used to define when extending [ expsionpanel ] The promotion of . This use [ kElevationToShadow ] To simulate shadows , It does not use. [ Material ] Any height characteristic of . By default , The value of elevation is 2.
How to achieve dart Code in file :
You need to implement it separately in your code :
stay
libCreate a folder calledmain.dartThe new dart file .
First , We will generate virtual data . We will create a list <Map<String, dynamic>> And add variables _ items Is equivalent to generating a list . In this list , We will add number、 id、 title、 description and isExpanded.
List<Map<String, dynamic>> _items = List.generate(
10,
(index) => {
'id': index,
'title': 'Item $index',
'description':
'This is the description of the item $index. Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'isExpanded': false
});
In the text , We will add ExpansionPanelList() The widget . In this widget , We will add an elevation of 3, Add... In parentheses expsioncallback Index and isExpanded. We will add setState () Method . In the method , We will add _ items [ index ][‘ isexpanded’] equal not isExpanded.
ExpansionPanelList(
elevation: 3,
expansionCallback: (index, isExpanded) {
setState(() {
_items[index]['isExpanded'] = !isExpanded;
});
},
animationDuration: Duration(milliseconds: 600),
children: _items
.map(
(item) => ExpansionPanel(
canTapOnHeader: true,
backgroundColor:
item['isExpanded'] == true ? Colors._cyan_[100] : Colors._white_,
headerBuilder: (_, isExpanded) => Container(
padding:
EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(
item['title'],
style: TextStyle(fontSize: 20),
)),
body: Container(
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(item['description']),
),
isExpanded: item['isExpanded'],
),
)
.toList(),
),
We will increase animationDuration by 600 millisecond . We will add child nodes , because variable_items Mapping to expsionpanel () The widget . In this widget , We will add canTapOnHeader was true,backgroundColor,headerBuilder return Container () The widget . In this widget , We're going to add padding , And add text to its sub attributes . In the text , We will add Conatiner And its sub attributes , We're going to add text . When we run the application , We should get screen output , Just like the screenshot below .

All the code
import 'package:flutter/material.dart';
import 'package:flutter_expansion_panel_list/splash_screen.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors._teal_,
),
home: Splash());
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List<Map<String, dynamic>> _items = List.generate(
10,
(index) => {
'id': index,
'title': 'Item $index',
'description':
'This is the description of the item $index. Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'isExpanded': false
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text('Flutter Expansion Panel List Demo'),
),
body: SingleChildScrollView(
child: ExpansionPanelList(
elevation: 3,
// Controlling the expansion behavior
expansionCallback: (index, isExpanded) {
setState(() {
_items[index]['isExpanded'] = !isExpanded;
});
},
animationDuration: Duration(milliseconds: 600),
children: _items
.map(
(item) => ExpansionPanel(
canTapOnHeader: true,
backgroundColor:
item['isExpanded'] == true ? Colors._cyan_[100] : Colors._white_,
headerBuilder: (_, isExpanded) => Container(
padding:
EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(
item['title'],
style: TextStyle(fontSize: 20),
)),
body: Container(
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(item['description']),
),
isExpanded: item['isExpanded'],
),
)
.toList(),
),
),
);
}
}
Conclusion
In this paper , I have simply explained ExpansionPanelList Basic structure ; You can modify this code according to your choice . This is a small introduction extension /panellist On User Interaction From my side , Its work uses Flutter.
Cat elder brother
-
WeChat ducafecat

版权声明
本文为[A cat that can make coffee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221146243618.html
边栏推荐
- 解决电脑连接正常,但浏览器无法打开网页的问题
- 深度迁移学习
- TS中通过变量存储key值读取对象的属性值时报错(TS: 7053)
- 半小时理解JSP
- 14天玩转51单片机第二天——以为咱们在玩LED灯?不不不,咱们在玩底层的输入输出^-^
- uniApp 学习笔记总结(一)
- PTC: 工程机械ESG产品研发重大变革
- 解决Command line is too long. Shorten command line for........错误
- Yunrong technology joined the dragon dragon dragon community to help the digital transformation of the financial industry
- 2021-09-17
猜你喜欢

软件究竟是如何传播的?

在安装mySQL出现这种问题如何解决呢?

Process pool create multi process Download Web page

Tamigou knowledge | process of equity transfer of new third board company

POSTGRESQL 15's new function is worth looking forward to, two of which make complaints about it for a long time.

编写最简单的字符设备驱动

看的懂的C语言--字符串、转义字符、注释

Why can't people see the truth?

MySQL 学习笔记

微信小程序使用VantUI框架(Vant Weapp) yarn安裝
随机推荐
Observe that the cloud enters the Alibaba cloud computing nest to build a stable and secure cloud connection for users
Redis login client command
synchronized实现和原理分析
FinBI连接本机mysql
Viewmodel源码解析
基于泰凌微TLSR825x的物联网解决方案之ibeacon开发总结
11.(地图数据篇)OSM数据如何下载使用
The second day of playing 51 single chip microcomputer in 14 days -- thought we were playing LED lights? No, no, no, we're playing with the bottom I / O^-^
[untitled]
第一章 入门概述
分支和循环语句
uniApp 学习笔记总结(一)
leetcode:347. 前 K 个高频元素
Redis environment installation
Wechat applet is installed using vant web yarn
一个可以让你斩获大厂Offer的笔记、速来领取
If you are in Russia under "technology sanctions", gbase
深度学习技术开发与应用
游戏+NFT,脱虚向实外的另一可行场景
8 条 写作 误区