Reputation: 80
I added dismissible widget in my listview flutter app. after adding it my stack layout widget become a dead code and the list is not showing in my app. it showing like 'instance of tasks'. but without dismissible the list is working fine. Please brother help me out from this problem. my code below-
@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
],
)
],
),
),
),
),
),
),
),
]),
]);
}),
),
],
),);
}
i expect my list that i make for firestore. but it's just showing -instance of 'tasks'
without dismissible the list is working.
Upvotes: 1
Views: 297
Reputation: 542
In your Code you are returning both Dismissible and Stack Widget try to put Dismissible Widget in to Stack
Upvotes: 1
Reputation: 10963
You're returning the Dismissible
and then returning the Stack
, but the code after returning the Dismissible
won't execute. You should put the Stack
in the Dismissible
child, replacing the ListTile
.
Like this:
@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
],
)
],
),
),
),
),
),
),
),
]),
]),
);
}),
),
],
),);
}
Upvotes: 1