common_data_table 1.0.7 copy "common_data_table: ^1.0.7" to clipboard
common_data_table: ^1.0.7 copied to clipboard

A Common Data Table same like data table with search filter, set limits, export excel / pdf and also edit, delete option and add more actions

example/lib/main.dart

import 'package:common_data_table/common_data_table.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Common Data Table Example',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({
    super.key,
  });

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CommonDataTable(
        isSearchAble: true,
        sortColumn: [1],
        title: "Testing Table",
        titleBgColor: Colors.black,
        titleStyle: TextStyle(
          fontSize: 16,
          color: Colors.white,
          fontWeight: FontWeight.bold,
        ),
        heading: [
          'S.NO',
          'Title',
          'Subtitle',
        ],
        rowActionButtons: [
          RowActionButton(
            tooltip: "View Image",
            icon: Icons.remove_red_eye,
            isDisabled: (index) {
              if (index == 3) {
                return true;
              }
              return null;
            },
            onTap: (index) {},
            color: Colors.blue,
          )
        ],
        tableActionButtons: [
          TableActionButton(
            child: Text("Add Highlight"),
            onTap: () {
              print("add");
            },
            shortcuts: SingleActivator(
              LogicalKeyboardKey.keyA,
              control: true,
            ),
            icon: Icon(
              FontAwesomeIcons.addressBook,
              size: 20,
            ),
          )
        ],
        rowBGColor: (index) {
          if (index.isOdd) {
            return Colors.red;
          }
          return null;
        },
        data: [
          for (int i = 1; i <= 100; i++) ...[
            [
              '$i.',
              'Title of $i',
              'Subtitle of title of $i',
            ],
          ]
        ],
        headingAlign: {
          0: TblAlign.center,
          1: TblAlign.center,
        },
        dataAlign: {
          0: TblAlign.center,
        },
        onEdit: (index) {},
        onDelete: (index) {},
        disabledDeleteButtons: [1, 3, 5],
        disabledEditButtons: [0, 2, 4],
        dataTextStyle: (row) {
          if (row[0] == '4.') {
            return {
              1: TextStyle(
                color: Colors.red,
                fontSize: 20,
              )
            };
          }
          return null;
        },
        onExportExcel: (file) async {
          await launchUrl(Uri.file(file.path));
        },
        onExportPDF: (file) async {
          await launchUrl(Uri.file(file.path));
        },
      ),
    );
  }
}
7
likes
140
pub points
58%
popularity

Publisher

unverified uploader

A Common Data Table same like data table with search filter, set limits, export excel / pdf and also edit, delete option and add more actions

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, font_awesome_flutter, path_provider, syncfusion_flutter_pdf, syncfusion_flutter_xlsio, visibility_detector

More

Packages that depend on common_data_table