medha_boards_table 0.0.2
medha_boards_table: ^0.0.2 copied to clipboard
A clean, architecture-focused table widget library with sorting, filtering, tree mode, frozen columns, and conditional formatting.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:medha_boards_table/medha_boards_table.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Tabular Flutter Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
darkTheme: ThemeData.dark(),
home: const TableExamplePage(),
);
}
}
class TableExamplePage extends StatefulWidget {
const TableExamplePage({super.key});
@override
State<TableExamplePage> createState() => _TableExamplePageState();
}
class _TableExamplePageState extends State<TableExamplePage> {
late TableController _controller;
@override
void initState() {
super.initState();
// Example: Create table from JSON (visualResponse format)
final jsonData = _getExampleTableJson();
_controller = TableController.fromJson(jsonData);
// Or create manually:
// _controller = TableController(
// config: TableConfig(
// visualType: 'table',
// title: 'Student Grades',
// columns: [...],
// fixedColumns: 2,
// ),
// data: [...],
// );
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
appBar: AppBar(
title: Text(_controller.state.config.title),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
setState(() {
_controller = TableController.fromJson(_getExampleTableJson());
});
},
),
],
),
body: TableWidget(
controller: _controller,
isDarkMode: isDarkMode,
),
);
}
/// Example table JSON in visualResponse format
Map<String, dynamic> _getExampleTableJson() {
return {
'visualType': 'table',
'title': 'Student Performance Report',
'fixedColumnWidth': 2,
'columnConfig': [
{
'title': 'Student ID',
'field': 'id',
'width': 120,
'headerSort': true,
'resizable': true,
'hozAlign': 'left',
},
{
'title': 'Name',
'field': 'name',
'width': 180,
'headerSort': true,
'resizable': true,
'headerFilter': 'input',
'headerFilterPlaceholder': 'Search name...',
},
{
'title': 'Math',
'field': 'math',
'columnType': 'numericColumn',
'width': 100,
'headerSort': true,
'resizable': true,
'hozAlign': 'right',
'formatterParams': {
'values': {
'decimalPoint': 1,
},
'conditionalFormatting': {
'type': 'gradient',
'style': 'background-color',
'basedOn': {
'field': 'math',
'solid': {
'lower_threshold': 60,
'higher_threshold': 90,
},
'gradient': {
'start': '#FF6B6B',
'mid': '#FFE66D',
'end': '#4ECDC4',
},
},
},
},
},
{
'title': 'Science',
'field': 'science',
'columnType': 'numericColumn',
'width': 100,
'headerSort': true,
'resizable': true,
'hozAlign': 'right',
'formatterParams': {
'values': {
'decimalPoint': 1,
},
},
},
{
'title': 'English',
'field': 'english',
'columnType': 'numericColumn',
'width': 100,
'headerSort': true,
'resizable': true,
'hozAlign': 'right',
'formatterParams': {
'values': {
'decimalPoint': 1,
},
},
},
{
'title': 'Average',
'field': 'average',
'columnType': 'numericColumn',
'width': 100,
'headerSort': true,
'resizable': true,
'hozAlign': 'right',
'formatterParams': {
'values': {
'decimalPoint': 2,
},
},
},
],
'rows': [
{
'id': 'S001',
'name': 'Alice Johnson',
'math': 95,
'science': 88,
'english': 92,
'average': 91.67,
},
{
'id': 'S002',
'name': 'Bob Smith',
'math': 78,
'science': 85,
'english': 80,
'average': 81.00,
},
{
'id': 'S003',
'name': 'Carol White',
'math': 92,
'science': 95,
'english': 89,
'average': 92.00,
},
{
'id': 'S004',
'name': 'David Brown',
'math': 65,
'science': 70,
'english': 68,
'average': 67.67,
},
{
'id': 'S005',
'name': 'Eve Davis',
'math': 88,
'science': 82,
'english': 91,
'average': 87.00,
},
],
};
}
}