flutter_fa_davi_table 1.0.1
flutter_fa_davi_table: ^1.0.1 copied to clipboard
A high-performance data table wrapper built on top of Davi. Optimized for lazy loading, infinite scrolling, and smart O(1) multi-platform grid rendering.
example/main.dart
import 'package:davi/davi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_artist_core/flutter_artist_core.dart';
import 'package:flutter_fa_davi_table/flutter_fa_davi_table.dart';
void main() {
runApp(const StandaloneTableApp());
}
/// A decoupled, standalone application showcasing [FaDaviTable] usage
/// completely isolated from any external state management ecosystem.
class StandaloneTableApp extends StatelessWidget {
const StandaloneTableApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FaDaviTable Standalone Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
),
home: const TableWorkspaceScreen(),
);
}
}
/// A mock entity model mapping a technical infrastructure server component.
class ServerNode {
final String id;
final String hostName;
final String ipAddress;
final String status;
const ServerNode({
required this.id,
required this.hostName,
required this.ipAddress,
required this.status,
});
}
/// The primary layout workspace maintaining clean identity states locally.
class TableWorkspaceScreen extends StatefulWidget {
const TableWorkspaceScreen({super.key});
@override
State<TableWorkspaceScreen> createState() => _TableWorkspaceScreenState();
}
class _TableWorkspaceScreenState extends State<TableWorkspaceScreen> {
/// Local source data array populated inside the table matrix view.
late List<ServerNode> _servers;
/// Structured column configurations definition container using DAVI 4.0.1 cellValue mapping.
late final FaDaviTableModelSettings<ServerNode> _tableSettings;
// === IDENTITY-BASED STATE VARIABLES ===
/// Tracks the explicit ID of the currently focused or inspected server entity.
String? _currentFocusedId;
/// Tracks primary table selection targets via unique entity key lookups.
final Set<String> _selectedIds = {};
/// Tracks custom checkbox toggles independently of structural row selections.
final Set<String> _checkedIds = {};
@override
void initState() {
super.initState();
// 1. Initialize mock dataset
_servers = [
const ServerNode(
id: 'srv-01',
hostName: 'us-east-prod-01',
ipAddress: '10.0.1.15',
status: 'Active',
),
const ServerNode(
id: 'srv-02',
hostName: 'us-west-stage-04',
ipAddress: '10.0.2.98',
status: 'Maintenance',
),
const ServerNode(
id: 'srv-03',
hostName: 'eu-central-core-02',
ipAddress: '192.168.1.5',
status: 'Active',
),
const ServerNode(
id: 'srv-04',
hostName: 'ap-south-edge-09',
ipAddress: '172.16.4.22',
status: 'Offline',
),
];
// 2. Build model settings map ensuring alignment with DAVI 4.0.1 cellValue specifications
_tableSettings = FaDaviTableModelSettings<ServerNode>(
columns: [
// Custom interactive checkbox column definition mapping identity tokens
DaviColumn<ServerNode>(
name: 'Check',
width: 65,
headerAlignment: Alignment.center,
cellAlignment: Alignment.center,
cellWidget: (param) {
final server = param.data;
final isChecked = _checkedIds.contains(server.id);
return Checkbox(
value: isChecked,
onChanged: (bool? cellValue) {
setState(() {
if (cellValue == true) {
_checkedIds.add(server.id);
} else {
_checkedIds.remove(server.id);
}
});
},
);
},
),
DaviColumn<ServerNode>(
name: 'Host Name',
cellValue: (param) => param.data.hostName,
grow: 1,
),
DaviColumn<ServerNode>(
name: 'IP Address',
cellValue: (param) => param.data.ipAddress,
width: 130,
),
DaviColumn<ServerNode>(
name: 'Operational Status',
cellValue: (param) => param.data.status,
width: 140,
),
],
);
}
/// Appends dummy data blocks onto the list layer simulating async network streaming operations.
void _simulateLazyLoadingBatch() {
setState(() {
final index = _servers.length + 1;
_servers = [
..._servers,
ServerNode(
id: 'srv-0$index',
hostName: 'dynamic-node-0$index',
ipAddress: '10.0.9.${10 + index}',
status: 'Active',
),
];
});
}
@override
Widget build(BuildContext context) {
// 3. Centralize layout decorations and reactive color behaviors into the theme configuration map
final centralizedTheme = FaDaviTableThemeData<ServerNode>(
columnDividerThickness: 0.5,
rowDividerThickness: 0.5,
rowDividerColor: Colors.grey.shade300,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.grey.shade300, width: 1),
borderRadius: BorderRadius.circular(8),
),
header: const HeaderThemeData(
color: Color(0xFFF5F7FA),
bottomBorderColor: Colors.black12,
),
// Centralized background coloring state matrix
rowColorBuilder:
(
server, {
required isCurrent,
required isSelected,
required isChecked,
required isHovered,
}) {
if (isHovered) return Colors.indigo.shade100.withValues(alpha: 0.1);
if (isCurrent) {
return Colors.indigo.shade200;
} else if (isSelected) {
return Colors.indigo.shade100;
} else if (isChecked) {
return Colors.green.shade50;
}
return Colors.white;
},
);
return Scaffold(
appBar: AppBar(
title: const Text('FaDaviTable Decoupled Example (v1.0.0)'),
backgroundColor: Colors.indigo.shade100,
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
setState(() {
_checkedIds.clear();
_selectedIds.clear();
_currentFocusedId = null;
});
},
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Status Monitor Banner displaying state data from the identity engine real-time
Card(
elevation: 0,
color: Colors.grey.shade100,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'• Current Active Target ID: ${_currentFocusedId ?? "None"}',
style: const TextStyle(fontWeight: FontWeight.w500),
),
Text('• Primary Grid Selected Keys: $_selectedIds'),
Text('• Custom Checkbox Checked Keys: $_checkedIds'),
],
),
),
),
const SizedBox(height: 12),
// Expanded reactive component table integration wrapper block
Expanded(
child: FaDaviTable<String, ServerNode>(
items: _servers,
getItemId: (server) => server.id,
sortRuleSide: SortRuleSide.viewSide,
columnWidthBehavior: ColumnWidthBehavior.scrollable,
visibleRowsCount: 10,
modelSettings: _tableSettings,
themeData: centralizedTheme,
// Inject local identity trackers directly into the composite core view parameters
currentItemId: _currentFocusedId,
selectedItemIds: _selectedIds,
checkedItemIds: _checkedIds,
placeholderWidget: const Center(
child: Text('No server nodes detected.'),
),
onRowTap: (server) {
setState(() {
_currentFocusedId = server.id;
// Coordinate multi-selection rule behavior via simple modifier mechanics
if (_selectedIds.contains(server.id)) {
_selectedIds.remove(server.id);
} else {
_selectedIds.add(server.id);
}
});
},
// Boundary intersection trigger pipeline automating endless scrolling setups smoothly
onLastVisibleRow: (lastRowIndex) {
debugPrint(
'Edge reached at row limit index: $lastRowIndex. Lazy loading triggered.',
);
_simulateLazyLoadingBatch();
},
),
),
],
),
),
);
}
}