dart + flutter 上有一个卡片小部件。翻转卡片时,isExpanded 状态被保留,这是不正确的。如何重置此条件?包 flutter_card_swiper。我通过回调和设置器都尝试过,也许我做错了什么。
class ExampleCard extends StatefulWidget {
final Person candidate;
const ExampleCard(
this.candidate, {
super.key,
});
@override
State<ExampleCard> createState() => _ExampleCardState();
}
class _ExampleCardState extends State<ExampleCard> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onVerticalDragUpdate: (details) {
if (details.delta.dy < 0) {
setState(() {
_isExpanded = true;
});
}
if (details.delta.dy > 0) {
setState(() {
_isExpanded = false;
});
}
},
child: Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 3,
blurRadius: 7,
offset: const Offset(0, 3),
),
],
),
alignment: Alignment.center,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(widget.candidate.imageUrl), fit: BoxFit.cover),
gradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFFD7E9F7), Color(0xFFD7E9F7)],
),
),
),
),
AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
height: _isExpanded ? MediaQuery.of(context).size.height * 0.30 : MediaQuery.of(context).size.height * 0.15,
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: CustomPaint(
painter: MyLinePainter(),
size: const Size(40, 3),
),
),
Text(
'${widget.candidate.name}, ${widget.candidate.age}',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
const SizedBox(height: 10),
if (_isExpanded)
Expanded(
child: Text(
'About me: ${widget.candidate.aboutMe}',
style: const TextStyle(color: Colors.grey, fontSize: 15),
),
),
],
),
),
),
],
),
),
);
}
}