Articles in this section
Category / Section

How to Add Multiple widgets in Flutter DataTable?

7 mins read

In this article, we will show how to add multiple widgets in Flutter DataTable.

Initialize the SfDataGrid widget with the necessary properties. To display multiple images or widgets in a cell, use the buildRow method within the DataGridSource. This method allows you to customize the widget displayed in each cell. Inside buildRow, you can add conditional logic for each column or cell to load the appropriate widgets or images.

@override
  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
      cells:
          row.getCells().map<Widget>((cell) {
            switch (cell.columnName) {
              case 'id':
                return Container(
                  padding: EdgeInsets.all(8.0),
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Icon(Icons.badge, color: Colors.blue),
                      SizedBox(width: 4),
                      Text(cell.value.toString()),
                    ],
                  ),
                );

              case 'name':
                return Container(
                  padding: EdgeInsets.all(8.0),
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      CircleAvatar(
                        radius: 12,
                        backgroundImage: AssetImage(
                          'images/GoldenState.png',
                        ),
                      ),
                      SizedBox(width: 6),
                      Text(cell.value.toString()),
                    ],
                  ),
                );

              case 'designation':
                return Container(
                  padding: EdgeInsets.all(4),
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Image.asset(
                        'images/DenverNuggets.png',
                        width: 20,
                        height: 20,
                      ),
                      SizedBox(width: 4),
                      Image.asset('images/Memphis.png', width: 20, height: 20),
                      SizedBox(width: 4),
                      Image.asset('images/Hornets.png', width: 20, height: 20),
                    ],
                  ),
                );

              case 'salary':
                return Container(
                  padding: EdgeInsets.all(8.0),
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Icon(Icons.monetization_on, color: Colors.green),
                      Text(cell.value.toString()),
                    ],
                  ),
                );

              default:
                return Container(
                  padding: EdgeInsets.all(8.0),
                  alignment: Alignment.center,
                  child: Text(cell.value.toString()),
                );
            }
          }).toList(),
    );
  }

You can download this example on GitHub.

Conclusion
I hope you enjoyed learning about How to add multiple widgets in Flutter DataTable.

You can refer to our Flutter DataTable feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Flutter DataTable example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied