Here is an example of Datatable in flutter.
Here is the complete code from main.dart file.
import 'package:flutter/material.dart';
main(List<String> args) {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@
override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: MyDataTable(),
),
);
}
}
class MyDataTable extends StatefulWidget {
const MyDataTable({Key? key}) : super(key: key);
@
override
State<MyDataTable> createState() => _MyDataTableState();
}
class _MyDataTableState extends State<MyDataTable> {
@
override
Widget build(BuildContext context) {
return Center(
child: DataTable(
columns: const [
DataColumn(label: Text('RollNo')),
DataColumn(label: Text('Name'))
],
rows: const [
DataRow(cells: [DataCell(Text('1')), DataCell(Text('Rama'))]),
DataRow(cells: [DataCell(Text('2')), DataCell(Text('Lakshmana'))]),
DataRow(cells: [DataCell(Text('3')), DataCell(Text('Sita'))])
],
));
}
}
Thanks,Srikanth