DEV Community

Cover image for Syncfusion Data Grid Flutter
Muhammad Manan
Muhammad Manan

Posted on


Syncfusion Data Grid Flutter

First things first before doing anything.
Add dependency

Add the Syncfusion Flutter DataGrid dependency to your pubspec.yaml file.

    syncfusion_flutter_datagrid: ^latest_version
Enter fullscreen mode Exit fullscreen mode

Get packages

Run the following command to get the required packages.

$ flutter pub get
Enter fullscreen mode Exit fullscreen mode

Import package

Import the following package in your Dart code.


import 'package:syncfusion_flutter_datagrid/datagrid.dart';
Enter fullscreen mode Exit fullscreen mode

Use whatever state management you want to use. I prefer provider so i am using that.

For this add the Provider dependency to your pubspec.yaml file.

    provider: ^latest_version
Enter fullscreen mode Exit fullscreen mode

Initialize the provider files in main.dart

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: multiProvider,
      child: MaterialApp(
        builder: (context, child) => MediaQuery(
          data: MediaQuery.of(context).copyWith(
            alwaysUse24HourFormat: true,
          child: child!,
        debugShowCheckedModeBanner: false,
        title: 'Data Grid',
        home: const Dashboard(),
Enter fullscreen mode Exit fullscreen mode

I prefer a global file for holding all providers, So make multi_provider.dart file and add the following code:

import 'package:provider/provider.dart';
import '../screens/dashboard/controller/dash_controller.dart';

var multiProvider = [

  /// DashProvider ///
    create: (_) => DashProvider(),
    lazy: true,


Enter fullscreen mode Exit fullscreen mode

After that we need to add our variables to dashboard provider, i am using a rest api for the data u can use firebase as well.
Add the following code to provider file:

// Initialize ur api service class
ApiService apiService = ApiService();

final GlobalKey<SfDataGridState> key = GlobalKey<SfDataGridState>();

bool _isLoading = false;
bool get isLoading => _isLoading;

//Add u header columns
  List<GridColumn> grid = [
        columnName: 'ID',
        label: Container(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            child:  Text(
              style: TextStyle(color: white),
              overflow: TextOverflow.ellipsis,

  late ReportDetailData reportDetailData;
  List<DataModel> _data = [];
  List<DataModel> get data => _data;

  Future<void> getData(BuildContext context) async {
    _isLoading = true;
    apiService.getData().then((response) {
      List<dynamic> data = json.decode(response.body);
      if (response.statusCode == 200 && data.toString() != "[]") {
        _data = => DataModel.fromJson(data)).toList();

        reportDetailData = ReportDetailData(data: _data);
        _isLoading = false;
      } else if (response.statusCode == 200 && data.toString() == "[]") {
        _isLoading = false;
      } else {
        _isLoading = false;
Enter fullscreen mode Exit fullscreen mode

After doing all that come to ur dashboard.dart file and call the api on initState.

Now Add the following code to initState:

  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {<DashProvider>().getData(context);
Enter fullscreen mode Exit fullscreen mode

For the widget part add the following code:

// Add this to the Scaffold body<DashProvider>().isLoading
            ? const Align(
                child: Text("Loading....),
            : SfDataGridTheme(
                    data: SfDataGridThemeData(headerColor:,
                    child: SfDataGrid(

                        gridLinesVisibility: GridLinesVisibility.both,
                        rowsPerPage: 20,
                        source: context
                        allowSorting: true,
                        columnWidthMode: ColumnWidthMode.fill,
                        selectionMode: SelectionMode.multiple,
                        navigationMode: GridNavigationMode.cell,
Enter fullscreen mode Exit fullscreen mode

And Finally don't forget to add the reportDetailData class..

Add the following code:

class ReportDetailData extends DataGridSource {
  /// Creates the employee data source class with required details.
  ReportDetailData({required List<DataModel> data}) {
    _employeeData =<DataGridRow>((DataModel e) {
      return DataGridRow(cells: <DataGridCell>[
            columnName: 'ID',
            value: == "null" ? "N/A" :,


  List<DataGridRow> _employeeData = <DataGridRow>[];

  List<DataGridRow> get rows => _employeeData;

  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((DataGridCell cell) {
      return Container(
        child: Text(
          style: TextStyle(fontSize: 15),
Enter fullscreen mode Exit fullscreen mode

That's all u need to do run the app by using the following command.

$flutter run
Enter fullscreen mode Exit fullscreen mode

Hurray u finally made a data grid using Syncfusion package flutter.

Final Result:
Image description

Keep sure to check out my packages and leave a suggestion:

Top comments (0)

Yes, this is technically an “ad”, but hear me out.

We have 900k+ developers reading, posting, and enjoying community, and would love to have you.

Create an account and continue your coding journey.