Flutter 打开ExpansionPanel颤振时如何更改标题
晚上好) 所以我在一个ExpansionFile中有一个ExpansionPanelist。我想在打开ExpansionPanelList的面板时更改标题,但是我该怎么做呢Flutter 打开ExpansionPanel颤振时如何更改标题,flutter,flutter-layout,Flutter,Flutter Layout,晚上好) 所以我在一个ExpansionFile中有一个ExpansionPanelist。我想在打开ExpansionPanelList的面板时更改标题,但是我该怎么做呢 return ExpansionPanel( headerBuilder: (BuildContext context, bool isExpanded) { return ListTile( title: isExp
return ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: isExpanded == null?
Text('No position found') //code if above statement is true
:Text("N"),
);
},
我发现我需要这样的东西,但是选中的条件一定是错误的,因为当我在ExpansionPanelList部分打开ExpansionPanel时,什么都没有发生
所以我的结构是这样的:
扩展文件
-扩展小组成员
-扩展面板
我想知道如何才能知道ExpansionPanelList中的ExpansionPanel是否打开&当我有这个信息时,我应该能够简单地将它传递到条件中
如果您想重新创建:(第55行开始于我上面发布的代码)
导入“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
家:脚手架(
正文:SingleChildScrollView(
子文件:扩展文件(
标题:文本(“Generelles Vorgehen”),
子项:[扩展列表()],
),
),
),
);
}
}
类ExpansionList扩展StatefulWidget{
最终信息;
常量扩展列表({
关键点,
这个.info,
}):super(key:key);
@凌驾
_ExpansionListState createState()=>\u ExpansionListState();
}
类_ExpansionListState扩展状态{
小部件_buildListPanel(){
返回ExpansionPanelist(
expansionCallback:(int索引,bool扩展){
设置状态(){
infos[index].isExpanded=!isExpanded;
});
},
子项:infos.map((Info){
返回扩展面板(
headerBuilder:(BuildContext上下文,bool isExpanded){
返回列表块(
标题:isExpanded==null?
Text('No position found')//如果上述语句为真,则编码
:文本(“N”),
);
},
正文:ListView.builder(
收缩膜:对,
itemCount:info.expandedValueData.length,
itemBuilder:(上下文,索引){
返回CheckboxListTile(
标题:文本(info.expandedValueData[index]。标题,
样式:TextStyle(
装饰:
信息。expandedValueData[索引]。已完成
?text.lineThrough
:null)),
值:info.expandedValueData[索引]。已完成,
一旦更改:(值){
设置状态(){
//在这里,您可以切换选中的项目状态
infos.firstWhere(
(currentInfo=>info==currentInfo)
..expandedValueData[索引]。已完成=值;
});
});
}),
iExpanded:info.iExpanded);
}).toList(),
);
}
@凌驾
小部件构建(构建上下文){
返回SingleChildScrollView(
子:容器(
子项:_buildListPanel(),
),
);
}
}
类扩展值{
int-id;
字符串标题;
布尔完成;
扩展值({
这个身份证,
这个名字,
this.completed=false,
});
}
班级信息{
字符串头值;
布尔展开;
最终列表扩展值数据;
信息({this.headerValue,this.isExpanded=false,this.expandedValueData});
}
列表信息=[
信息(
headerValue:“Außenasicht”,
expandedValueData:[
expandedValue(id:1,标题:“Roststellen”),
扩展值(
id:2,
标题:
“Farbunterschiede im Lack,unrelmäßigkeiten[Problemstellenübermalt]”,
扩展值(
id:3,
标题:“kleine Kratzer[腹地卡洛塞里·格里尔·福尔格什登]”,
扩展值(
id:4,
标题:“Dichtungen an Scheiben&Türen[porös,rissig]”,
扩展值(
id:5,
标题:
“沃拉勒姆·温德楚茨基·奥夫·克拉泽·乌特斯切恩[Gefahr gröerer Rissbildung]”,
扩展值(
id:6,
标题:
“Lampen untersuchen,funktionsfähig?Innen beschlagene Scheinwerfer[Gefahr durch Wasserschaden]”,
扩展值(
id:7,
标题:“Reifen[Risse o.abgefahrenes Profil?]”,
],
),
信息(
headerValue:“Innenraum”,
expandedValueData:[
扩展值(
id:1,
标题:“你是谁?”,
expandedValue(id:2,标题:“funktionierende Elektrik”),
expandedValue(id:3,标题:“Sitze”),
expandedValue(id:4,标题:“剩余”),
],
),
信息(
headerValue:“Motorraum”,
expandedValueData:[
扩展值(
id:1,
标题:
“沃姆格劳芬汽车厂?【事件解决方案启动问题】”,
扩展值(
id:2,
标题:“Batteriepole angerostet?[Gefahr vorzeitiger Entladung]”,
扩展值(
id:3,
标题:“吉布斯·奥德·布雷姆斯福·斯吉吉斯普雷恩:”,
扩展值(
id:4,
标题:
“斯普劳代尔Kühlswasser bei laufendem汽车公司[eventuell Zylinderkopfdichtung defekt]”,
expandedValue(id:5,标题:“Ölstand prüfen”),
],
),
信息(
headerValue:“Unterboden”,
expandedValueData:[
expandedValue(id:1,标题:“Roststellen?”),
扩展值(
id:2,
标题:
“诺伊尔·乌特
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: SingleChildScrollView(
child: ExpansionTile(
title: Text("Generelles Vorgehen"),
children: [ExpansionList()],
),
),
),
);
}
}
class ExpansionList extends StatefulWidget {
final Info info;
const ExpansionList({
Key key,
this.info,
}) : super(key: key);
@override
_ExpansionListState createState() => _ExpansionListState();
}
class _ExpansionListState extends State<ExpansionList> {
Widget _buildListPanel() {
return ExpansionPanelList(
expansionCallback: (int index, bool isExpanded) {
setState(() {
infos[index].isExpanded = !isExpanded;
});
},
children: infos.map<ExpansionPanel>((Info info) {
return ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: isExpanded == null?
Text('No position found') //code if above statement is true
:Text("N"),
);
},
body:ListView.builder(
shrinkWrap: true,
itemCount: info.expandedValueData.length,
itemBuilder: (context, index) {
return CheckboxListTile(
title: Text(info.expandedValueData[index].title,
style: TextStyle(
decoration:
info.expandedValueData[index].completed
? TextDecoration.lineThrough
: null)),
value: info.expandedValueData[index].completed,
onChanged: (value) {
setState(() {
// Here you toggle the checked item state
infos.firstWhere(
(currentInfo) => info == currentInfo)
..expandedValueData[index].completed = value;
});
});
}),
isExpanded: info.isExpanded);
}).toList(),
);
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
child: _buildListPanel(),
),
);
}
}
class expandedValue {
int id;
String title;
bool completed;
expandedValue({
this.id,
this.title,
this.completed = false,
});
}
class Info {
String headerValue;
bool isExpanded;
final List<expandedValue> expandedValueData;
Info({this.headerValue, this.isExpanded = false, this.expandedValueData});
}
List<Info> infos = [
Info(
headerValue: "Außenansicht",
expandedValueData: <expandedValue>[
expandedValue(id: 1, title: "Roststellen"),
expandedValue(
id: 2,
title:
"Farbunterschiede im Lack, Unregelmäßigkeiten [Problemstellen übermalt]"),
expandedValue(
id: 3,
title: "kleine Kratzer [hinter Karosserie größere Folgeschäden?]"),
expandedValue(
id: 4,
title: "Dichtungen an Scheiben & Türen [porös, rissig]"),
expandedValue(
id: 5,
title:
"Vorallem Windschutzscheibe auf Kratzer untersuchen [Gefahr größerer Rissbildung ]"),
expandedValue(
id: 6,
title:
"Lampen untersuchen, funktionsfähig? Innen beschlagene Scheinwerfer [Gefahr durch Wasserschaden]"),
expandedValue(
id: 7,
title: "Reifen [Risse o. abgefahrenes Profil?]"),
],
),
Info(
headerValue: "Innenraum",
expandedValueData: <expandedValue>[
expandedValue(
id: 1,
title: "klappern Türen oder deren Seitenverkleidung beim Schließen?"),
expandedValue(id: 2, title: "funktionierende Elektrik"),
expandedValue(id: 3, title: "Sitze"),
expandedValue(id: 4, title: "Rest"),
],
),
Info(
headerValue: "Motorraum",
expandedValueData: <expandedValue>[
expandedValue(
id: 1,
title:
"Motor schon vom Verkäufer warmgelaufen? [eventuell sollen Startprobleme vertuscht werden]"),
expandedValue(
id: 2,
title: "Batteriepole angerostet? [Gefahr vorzeitiger Entladung]"),
expandedValue(
id: 3,
title: "Gibt es Öl oder Bremsflüssigkeitsspuren an:"),
expandedValue(
id: 4,
title:
"Sprudelt Kühlswasser bei laufendem Motor [eventuell Zylinderkopfdichtung defekt]"),
expandedValue(id: 5, title: "Ölstand prüfen"),
],
),
Info(
headerValue: "Unterboden",
expandedValueData: <expandedValue>[
expandedValue(id: 1, title: "Roststellen?"),
expandedValue(
id: 2,
title:
"neuer Unterbodenschutz? [möglicher Versuch Problemstellen zu verdecken (z.B Schweißnähte etc.)]"),
expandedValue(
id: 3,
title: "sitzt der Auspuff fest, arbeitet der Motor leise?"),
],
),
Info(
headerValue: "Dokumenten- & Zahlencheck",
expandedValueData: <expandedValue>[
expandedValue(
id: 1, title: "Reperaturenabrechnungen vorhanden?"),
expandedValue(
id: 2,
title:
"macht Laufleistung Sinn? Mögliche Lufleistungen im Bereich von über 150 000 km, wenn:"),
expandedValue(
id: 3, title: "Zulassungsbescheinigung Teil 1&2 "),
expandedValue(id: 4, title: "Wartungen & Rechnungen"),
],
),
Info(
headerValue: "Probefahrt",
expandedValueData: <expandedValue>[
expandedValue(id: 1, title: "vor der Fahrt:"),
expandedValue(id: 2, title: "bei der Fahrt"),
expandedValue(id: 3, title: "nach der Fahrt"),
],
),
Info(
headerValue: "Garantie, Gewehrleistung und Vertrag ",
expandedValueData: <expandedValue>[
expandedValue(
id: 1,
title:
"auf Rechmäßigkeit prüfen, wegen Haftungsgründen verweisen wir hier auf andere Seiten, wie die der Allianz oder Cosmosdirekt o. ä. "),
],
),
];