'Flutter how to collapse ExpansionTile on child button click?
After hours of researching, I've come to a stressed place where I need to ask a question here.
I'm simply trying to collapse an ExpansionTile on button click but it is not working. The Expansion Tile is nested in a ListView.
Flexible(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0, vertical: 8.0),
child: Container(
// color: white,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: light == true ? yellow : blue,
boxShadow: [
BoxShadow(
color: light == true ? yellow : blue,
spreadRadius: 0),
],
),
child: ExpansionTile(
initiallyExpanded: false,
// childrenPadding: EdgeInsets.all(1),
key: GlobalKey(),
title: Padding(
padding: const EdgeInsets.all(3.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.wb_sunny,
color: Colors.yellow, // Colors.yellow
size: 28.1,
),
Text(
' Wake up',
style: TextStyle(
fontWeight: FontWeight.bold,
color: light == true
? blue
: Colors.white,
fontSize: 15.0,
fontFamily: 'poppins'),
),
],
),
Text(
_wakeuptime_time_friendly,
style: TextStyle(
color: light == true
? blue
: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15.0),
),
],
),
),
children: <Widget>[
Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Padding(
padding:
const EdgeInsets.all(12.0),
child: _wakeup_routine_daily_bool
? Center(
child: Text(
'Good job!',
style: TextStyle(
color: light ==
true
? blue
: Colors
.white,
fontWeight:
FontWeight
.bold,
fontSize: 22.0),
),
)
: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
style: light == true
? raisedButtonStyleBlue
: raisedButtonStyleYellow,
onPressed: () async {
// db query
setState(() {
});
},
child: const Text(
'Done!',
style: TextStyle(
fontWeight:
FontWeight
.bold,
fontSize: 18.0),
),
),
ElevatedButton(
style: light == true
? raisedButtonStyleBlue
: raisedButtonStyleYellow,
onPressed: () async {
setState(() {
});
},
child: const Text(
'Missed',
style: TextStyle(
fontWeight:
FontWeight
.bold,
fontSize: 18.0),
),
),
],
)
],
),
),
],
),
],
),
),
),
),
With both ElevatedButton widgets in the onClick(), I'm trying to collapse ExpansionTile. Any help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
