Reputation: 359
I am trying to use Googles's chart lib (https://github.com/google/charts) to make same charts. My problem is the following: I am trying to have the chart on the top, followed by buttons in text.
But everytime, if I try to do the chart in a column like:
Column(
children: [
LineChart(seriesList),
],
);
}
I need to wrap the LineChart in an expanded (what I not really want), so I do not get an error. Is there any option, to force the google-charts to a specific size, e.g. half of the screen?
Upvotes: 0
Views: 371
Reputation: 8383
There are plenty of different ways.
AspectRatio
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
AspectRatio(
aspectRatio: 2 * MediaQuery.of(context).size.aspectRatio,
child: SimpleLineChart.withSampleData(),
),
],
),
);
}
}
SizedBox
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height / 2,
child: SimpleLineChart.withSampleData()),
],
),
);
}
}
ConstrainedBox
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
ConstrainedBox(
constraints: BoxConstraints.loose(Size(
double.infinity,
MediaQuery.of(context).size.height / 2,
)),
child: SimpleLineChart.withSampleData()),
],
),
);
}
}
ListView
, specifying the itemExtent
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
itemExtent: MediaQuery.of(context).size.height / 2,
children: [
SimpleLineChart.withSampleData(),
],
),
);
}
}
...
...
Upvotes: 1