Skip to content

Instantly share code, notes, and snippets.

@imaNNeo
Created December 3, 2021 21:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imaNNeo/336b1674e3036e626ec475fe2ad10afe to your computer and use it in GitHub Desktop.
Save imaNNeo/336b1674e3036e626ec475fe2ad10afe to your computer and use it in GitHub Desktop.
PieChart dyanmic radius
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'fl_chart Pie Chart Sizing Bug',
home: Scaffold(
appBar: AppBar(
title: Text('fl_chart Pie Chart Sizing Bug'),
),
body: Container(
width: 300.0,
height: 300.0,
color: Colors.blue,
child: LayoutBuilder(
builder: (context, constraints) {
final shortestSide = constraints.biggest.shortestSide;
return PieChart(
PieChartData(
sections: [
PieChartSectionData(
value: 60.0,
color: Colors.green,
radius: shortestSide / 2,
),
PieChartSectionData(
value: 40.0,
color: Colors.purple,
radius: shortestSide / 2,
),
],
centerSpaceRadius: 0,
),
);
},
),
)),
);
}
}
@imaNNeo
Copy link
Author

imaNNeo commented Dec 3, 2021

pie_dynamic_radius.mp4

@Hary309
Copy link

Hary309 commented Sep 25, 2022

Thanks, it works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment