Table Widget in Flutter

Table widgets are used to arrange things in a table layout. There is no need to utilise Rows and Columns to build a table. If we have numerous rows with columns that are the same width, the Table widget is the best option.

In this article, you will learn how to create your Table widget in Flutter. So let’s take one example of the Table  in Flutter of Mobile application

Step-by-Step Implementation

Step 1: Create a New Project in Android Studio (File >new flutter project).


Step 2: Adding material package 

Import method the runApp method in the main function call first while run the application.

 import 'package:flutter/material.dart';

 void main() {

     runApp(RunMyApp());

 }

Step 3: Creating a stateless widget  

 We can create a stateless widget that contains MaterialApp widget,AppBar,etc.

 class RunMyApp extends StatelessWidget {

     const RunMyApp({super.key});  

    @override

    Widget build(BuildContext context) {

    return MaterialApp(home);

     }

 }

Step 4: Below code write a table in a flutter.
 TableRow(children: [
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
]),
TableRow(children: [
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
]),
TableRow(children: [
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
])
Step 5: Final code of Table.
 import 'package:flutter/material.dart';
void main() {
runApp(tableview());
}

class tableview extends StatefulWidget {
@override
_TableExample createState() => _TableExample();
}

class _TableExample extends State<tableview> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Flutter Table'),
),
body: Center(
child: Column(children: <Widget>[
Container(
margin: EdgeInsets.all(5),
child: Table(
defaultColumnWidth: FixedColumnWidth(100.0),
border: TableBorder.all(
color: Colors.black, style: BorderStyle.solid, width: 1),
children: [
TableRow(children: [
Column(children: [
Text('Test ', style: TextStyle(fontSize: 15.0))
]),
Column(children: [
Text('Test ', style: TextStyle(fontSize: 15.0))
]),
Column(children: [
Text('Test', style: TextStyle(fontSize: 15.0))
]),
]),
TableRow(children: [
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
]),
TableRow(children: [
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
]),
TableRow(children: [
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
Column(children: [Text('Test')]),
]),
],
),
),
]))),
);
}
}
Step 6: Output of above example.

Happy coding!

365Bloggy June 14, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive