Last active
March 21, 2020 11:37
-
-
Save Abhilash-Chandran/ff5f25d3b79fd6e09ca4be335db031ad to your computer and use it in GitHub Desktop.
Adjust height on long press.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
final List<MeetingCard> _meetingCards = [ | |
MeetingCard(title: 'standup meeitng'), | |
MeetingCard(title: 'weekely meeting'), | |
MeetingCard(title: 'Status Meeting'), | |
MeetingCard(title: 'Another meeting'), | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Adjustable height card.', | |
home: ListView.builder( | |
itemCount: _meetingCards.length, | |
itemBuilder: (context, index){ | |
return _meetingCards[index]; | |
} | |
), | |
); | |
} | |
} | |
// Define a custom Form widget. | |
class MeetingCard extends StatefulWidget { | |
final String title; | |
MeetingCard({this.title}); | |
@override | |
_MeetingCardState createState() => _MeetingCardState(); | |
} | |
// Define a corresponding State class. | |
class _MeetingCardState extends State<MeetingCard> { | |
// this height is specific to this widget. | |
double height = 130; | |
@override | |
Widget build(context) { | |
return GestureDetector( | |
onLongPress: (){ | |
setState((){ | |
height = height == 130 ? 150 : 130; | |
}); | |
}, | |
child: AnimatedContainer( | |
duration: new Duration(milliseconds: 500), | |
height: height, | |
child: Card(child: Center(child: Text(widget.title),),), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment