Skip to content

Instantly share code, notes, and snippets.

@Abhilash-Chandran
Last active March 21, 2020 11:37
Show Gist options
  • Save Abhilash-Chandran/ff5f25d3b79fd6e09ca4be335db031ad to your computer and use it in GitHub Desktop.
Save Abhilash-Chandran/ff5f25d3b79fd6e09ca4be335db031ad to your computer and use it in GitHub Desktop.
Adjust height on long press.
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