Почему мой виджет сохраняет состояние, когда я прокручиваю карты? ⇐ Android
-
Anonymous
Почему мой виджет сохраняет состояние, когда я прокручиваю карты?
Scrolling through the cards requires the additional information to be closed again. how do I accomplish this?
I tried using a setter and tried adding a callback, it didn't help, maybe I was doing something wrong? Also I'm just pouring water into the question because the bad stackoverflow system won't let me send the question because darth has a huge boilerplate and the code really comes out a lot, and there's nothing to cut anymore. What do u want from me, dear stackoverfow???
class ExampleCard extends StatefulWidget { final Person candidate; const ExampleCard( this.candidate, { super.key, }); @override State createState() => _ExampleCardState(); } class _ExampleCardState extends State { 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), ), ), ], ), ), ), ], ), ), ); } }
Источник: https://stackoverflow.com/questions/780 ... wipe-cards
Scrolling through the cards requires the additional information to be closed again. how do I accomplish this?
I tried using a setter and tried adding a callback, it didn't help, maybe I was doing something wrong? Also I'm just pouring water into the question because the bad stackoverflow system won't let me send the question because darth has a huge boilerplate and the code really comes out a lot, and there's nothing to cut anymore. What do u want from me, dear stackoverfow???
class ExampleCard extends StatefulWidget { final Person candidate; const ExampleCard( this.candidate, { super.key, }); @override State createState() => _ExampleCardState(); } class _ExampleCardState extends State { 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), ), ), ], ), ), ), ], ), ), ); } }
Источник: https://stackoverflow.com/questions/780 ... wipe-cards
Мобильная версия