Flutter Chart Magic with fl_chart #1

Ece
3 min readDec 29, 2023

--

Hey heyy! During these articles, I’m going to show you how to use ‘fl_chart’ to create different types of charts. Each article will focus on one type of chart. I’ll start simple with things like line charts and pie charts, and then I’ll get more advanced, exploring all the cool stuff you can do with the charts.

Why Use fl_chart?

‘fl_chart’ is like a magic wand for making chart in Flutter. It’s super easy to use, even if I’m just starting out. Plus, it lets me make all kinds of charts that look awesome and showcase my data in an exciting manner.

Line Charts

Line charts in Flutter with ‘fl_chart’ are like a visual journey through your data story. They connect dots to show how things change or grow. Imagine them as your data’s adventure, perfect for showcasing trends or ups and downs. And the best part? You can make these charts look awesome and match your app’s vibe!

Step 1: Add the dependencies to pubspec.yaml file

fl_chart: ^0.65.0

Step 2: Create HomePage

In the ‘home_page.dart’ file, let’s craft three buttons to explore our examples. In the ‘routes.dart’ file I’ve set up navigation to our examples, you can check out the source code for details.

HomePage
HomePage

Step 3: Import the package and start to code

import 'package:fl_chart/fl_chart.dart';

Afterward, we’ll create our first example, following a similar code structure with a clear separation between ‘view’ and ‘widget’. We’re starting with ‘view’ part.

FirstLineChart

Create ‘first_line_chart.dart’ file inside the ‘views’ in ‘lib’ folder.

FirstLineChartPage

Next in line, let’s explore our second example together!

SecondLineChart

Create ‘second_line_chart.dart’ file inside the ‘views’ in ‘lib’ folder.

SecondLineChartPage

We’re almost there, and for the grand finale, the last example gets a bit fancy with animations!

ThirdLineChart

Create ‘third_line_chart.dart’ file inside the ‘views’ in ‘lib’ folder.

ThirdLineChartPage

Thanks for joining me on this fl_chart journey in Flutter! We’ve covered simple to more exciting chart examples. With fl_chart, your app’s data can shine brightly. Have fun, play around, and make those charts yours! Keep exploring the charting magic in Flutter. Happy coding until next time!

--

--

Ece

A landscape architect who discovered a passion for building mobile apps using Flutter. Currently based in Izmir