nrb 1.0.12
nrb: ^1.0.12 copied to clipboard
A Flutter package for building structured and customizable report layouts.
example/lib/main.dart
import 'dart:io' show Directory, File;
import 'package:flutter/foundation.dart' show kIsWeb, kDebugMode;
import 'package:flutter/material.dart';
import 'package:nrb/nrb.dart';
void main() {
runApp(MyReportBuilderApp());
}
class MyReportBuilderApp extends StatefulWidget {
const MyReportBuilderApp({super.key});
@override
State<MyReportBuilderApp> createState() => _MyReportBuilderAppState();
}
class _MyReportBuilderAppState extends State<MyReportBuilderApp> {
// 1. Create the controller
final ReportController _reportController = ReportController();
final List<HeaderCell> headers = [
HeaderCell(text: "Secondary", span: 3, backgroundColor: Colors.green),
HeaderCell(text: "Primary", span: 3, backgroundColor: Colors.green),
];
final List<SubHeaderCell> subHeaders = [
SubHeaderCell(text: "Target", backgroundColor: Colors.green, foregroundColor: Colors.white,),
SubHeaderCell(text: "Actual", backgroundColor: Colors.green, foregroundColor: Colors.white,),
SubHeaderCell(text: "%", backgroundColor: Colors.green, foregroundColor: Colors.white,),
SubHeaderCell(text: "Target", backgroundColor: Colors.green, foregroundColor: Colors.white,),
SubHeaderCell(text: "Actual", backgroundColor: Colors.green, foregroundColor: Colors.white,),
SubHeaderCell(text: "%", backgroundColor: Colors.green, foregroundColor: Colors.white,),
];
final leftColumns = [
TextCell(itemContent: "01-Nov-2025"),
TextCell(itemContent: "02-Nov-2025"),
TextCell(itemContent: "03-Nov-2025"),
TextCell(itemContent: "04-Nov-2025"),
TextCell(itemContent: "05-Nov-2025"),
];
final tableData = [
[
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextFieldCell(initialValue: "85.07%"),
],
[
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
],
[
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
],
[
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
],
[
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
TextCell(itemContent: "10,99,493", textAlignment: Alignment.centerRight),
TextCell(itemContent: "9,34,839", textAlignment: Alignment.centerRight),
TextCell(itemContent: "85.07%"),
],
];
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(title: const Text('Report Builder')),
body: SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: ReportMaker(
headers: headers,
subHeaders: subHeaders,
leftColumn: leftColumns,
tableData: tableData,
stickyHeaderLabel: "Tran",
stickyHeaderBackgroundColor: Colors.green,
enableDownload: true,
showDownloadFloatingButton: true,
packageName: "com.innovatenestlabs.example", // <-- ADD THIS
controller: _reportController,
onDownloadCompleted: (bytes, fileName) async {
if (kIsWeb) {
// WebSaveHelper.saveFile(bytes, fileName);
if (kDebugMode) {
print("in Web");
}
} else {
// MOBILE/DESKTOP LOGIC (dart:io is safe here)
final directory = Directory('/storage/emulated/0/Download');
if (!await directory.exists()) {
await directory.create(recursive: true);
}
final file = File('${directory.path}/$fileName');
await file.writeAsBytes(bytes);
if (kDebugMode) {
print('File saved to: ${file.path}');
}
}
},
),
),
const SizedBox(height: 5,),
ElevatedButton(
onPressed: () {
// 3. Trigger data extraction!
List<List<String>> finalData = _reportController.getSubmitData();
if (kDebugMode) {
print(finalData[0][6]);
}
},
child: Text("Submit Report"),
)
],
),
),
),
);
}
}