gpt4 book ai didi

flutter - 添加可弃用后,我的堆栈布局小部件变得死了

转载 作者:行者123 更新时间:2023-12-03 03:25:13 25 4
gpt4 key购买 nike

我在listview flutter应用程序中添加了可忽略的小部件。添加它后,我的堆栈布局小部件变为无效代码,并且该列表未显示在我的应用中。
它显示为“任务实例”。但在不容忽视的情况下,该列表可以正常工作。请兄弟帮我解决这个问题。我的代码如下-

@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomInset: false,
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
_myAppBar(context),
Container(
width: MediaQuery
.of(context)
.size
.width,
height: MediaQuery
.of(context)
.size
.height - 80,
child: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];

return Dismissible(
// Each Dismissible must contain a Key. Keys allow Flutter to
// uniquely identify widgets.
key: new ObjectKey(items[index]),
// Provide a function that tells the app
// what to do after an item has been swiped away.
onDismissed: (direction) {
// Remove the item from the data source.
setState(() {
items.removeAt(index);
});

// Then show a snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
// Show a red background as the item is swiped away.
background: Container(color: Colors.red),
child: ListTile(title: Text('$item')),
);


return Stack(children: <Widget>[
// The containers in the background
Column(children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: Container(
width: MediaQuery
.of(context)
.size
.width,
height: 80.0,
child: Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Material(
color: Colors.white,
elevation: 14.0,
shadowColor: Color(0x802196F3),
child: Center(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
todoType('${items[index].tasktype}'),
Text(
'${items[index].taskcustomername}',
style: TextStyle(
color: Colors.black,
fontSize: 20.0),
),
Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Text(
'${items[index].taskcustomeruserid}',
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
fontWeight: FontWeight.bold),
),
Text(
'${items[index].taskcustomermobileno}',
style: TextStyle(
color: Colors.black,
fontSize: 16.0),
),
// ..........................dismiss


//.................end dismiss


],
)
],
),
),
),
),
),
),
),
]),


]);
}),
),
],
),);
}

我希望我为消防局做的 list 。
但这只是显示“任务”的实例

在不容忽视的情况下,该列表正在运行。

最佳答案

您先返回Dismissible,然后返回Stack,但是返回Dismissible之后的代码将无法执行。您应该将Stack放在Dismissible子级中,代替ListTile

像这样:

@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomInset: false,
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
_myAppBar(context),
Container(
width: MediaQuery
.of(context)
.size
.width,
height: MediaQuery
.of(context)
.size
.height - 80,
child: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];

return Dismissible(
// Each Dismissible must contain a Key. Keys allow Flutter to
// uniquely identify widgets.
key: new ObjectKey(items[index]),
// Provide a function that tells the app
// what to do after an item has been swiped away.
onDismissed: (direction) {
// Remove the item from the data source.
setState(() {
items.removeAt(index);
});

// Then show a snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
// Show a red background as the item is swiped away.
background: Container(color: Colors.red),
child: Stack(children: <Widget>[
// The containers in the background
Column(children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: Container(
width: MediaQuery
.of(context)
.size
.width,
height: 80.0,
child: Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Material(
color: Colors.white,
elevation: 14.0,
shadowColor: Color(0x802196F3),
child: Center(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
todoType('${items[index].tasktype}'),
Text(
'${items[index].taskcustomername}',
style: TextStyle(
color: Colors.black,
fontSize: 20.0),
),
Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Text(
'${items[index].taskcustomeruserid}',
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
fontWeight: FontWeight.bold),
),
Text(
'${items[index].taskcustomermobileno}',
style: TextStyle(
color: Colors.black,
fontSize: 16.0),
),
// ..........................dismiss


//.................end dismiss


],
)
],
),
),
),
),
),
),
),
]),


]),
);

}),
),
],
),);
}

关于flutter - 添加可弃用后,我的堆栈布局小部件变得死了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58470691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com