0

when I try to data in the list it's showing

But I m not able to show it in the data table.

Listview

import 'package:flutter/material.dart';
import 'package:flutter_sample/src/data/models/emp_data.dart';

class ListingData extends StatelessWidget {
final List<ListData> emp;

const ListingData({Key? key,required this.emp}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListView.builder(
  itemCount: emp.length,
  itemBuilder: (context, index) {
    final empData = emp[index];
    return ListTile(
      title: Text('${empData.emp_name}'),
      subtitle: Text('${empData.designation}'),
    );
  },
);
}
}

i want to try with data table same data

example code

return DataTable(

  columns: const <DataColumn>[
    DataColumn(
      label: Text(
        'ID',
      ),
    ),
    DataColumn(
      label: Text(
        'Name',
      ),
    ),
    DataColumn(
      label: Text(
        'Role',
      ),
    ),
  ],


  rows: const <DataRow>[
    DataRow(
      cells: <DataCell>[
        DataCell(Text('${empData.id}'),
        DataCell(Text('${empData.emp_name}')),
   
      ],
    ),


  ],
);

I don't know how to get index values and data to set columns.

this thing how to set as the data table

itemCount: emp.length,
itemBuilder: (context, index) {
final empData = emp[index];

can anyone suggest to me the proper way to do

2
  • you are trying to create table? Can you include your data? Commented Jan 24, 2022 at 16:27
  • @yeasin Sheikh i have included data. Data is coming in the list, now i want to change to table. row i cant put please give me way to show the data Commented Jan 24, 2022 at 16:36

1 Answer 1

2

Define rows as follows:

  rows: List.generate(
        emp.length,
        (index) => empDataRow(
            emp[index],
            )),

And define datarows(Here empDataRow) as follows where Employee your empData's class:

   DataRow empDataRow(Employee empData) {
     return DataRow(
            cells: <DataCell>[
               DataCell(Text('${empData.id}'),
               DataCell(Text('${empData.emp_name}')),
             ],),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.