Reputation: 73
I am trying to set the height and width of a card like below, but it is returning error: "the named parameter is not defined" for both height and width. Is this an incorrect way to set card height and width?
Widget build(BuildContext context) { final ThemeData theme = Theme.of(context);
return new WillPopScope(
onWillPop: () => _onBackPressed(context),
child: Scaffold(
appBar: new AppBar(
title: new Text(
'Finding your pizza',
style: theme.textTheme.title,
),
),
body: new Card(
width: MediaQuery.of(context).size.width/60,
height: MediaQuery.of(context).size.height/60,
child: new Center(
child: new Column(
children: <Widget>[
Upvotes: 0
Views: 819
Reputation: 956
If a container is overkill, you may also use a SizedBox
widget to set width and height as well.
final double cardWidth = MediaQuery.of(context).size.width/60;
final double cardHeight = MediaQuery.of(context).size.height/60,
Widget build(BuildContext context) {
...
SizedBox(
width: cardWidth,
height: cardHeight,
child: Card(child: Text('Hello World!')),
),
...
}
Upvotes: 1
Reputation: 80914
According to the docs, the Card
class does not contain neither height
nor width
named parameter.
You can use a Container
that will have both height
and width
:
Widget build(BuildContext context) {
return Center(
child: Card(
child: InkWell(
splashColor: Colors.blue.withAlpha(30),
onTap: () {
print('Card tapped.');
},
child: Container(
width: 300,
height: 100,
child: Text('A card that can be tapped'),
),
),
),
);
}
Upvotes: 0