mahop_data_table 1.0.1 copy "mahop_data_table: ^1.0.1" to clipboard
mahop_data_table: ^1.0.1 copied to clipboard

Flutter Widget to display a DataTable, ListView, TreeView (Pro), TreeListView (Pro), with many options, editing, advanced drag and drop support and much more.

example/example.dart

import 'package:flutter/material.dart';
import 'package:mahop_data_table/mh_items_view/mh_items_view.dart';
import 'package:mahop_data_table/mh_items_view/mh_items_view_settings.dart';
import 'package:mahop_data_table/mh_text/mh_title_medium.dart';

/// More samples you can find in our examples app
/// https://flutterdemo.mahop.net
/// Every sample has also the code attached to be coppied
void main() {
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Data Table Example',
      home: MyHomePage(title: 'MaHop Flutter Data Table Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // --------------------------------------------
    // - Build some sample data
    // --------------------------------------------
    final List<ExampleItem> items = [];
    for (var i = 1; i <= 100; i++) {
      items.add(ExampleItem(text: "Example Item $i", index: i));
    }

    // --------------------------------------------
    // - Build the Column definitions you need
    // --------------------------------------------
    List<MhItemsViewColumnDef<ExampleItem>> columnDefs = [];
    columnDefs.add(MhItemsViewColumnDef<ExampleItem>(
        id: "index",
        header: "Index",
        columnWidth: 50,
        getDisplayValue: (item) => item.index));
    columnDefs.add(MhItemsViewColumnDef<ExampleItem>(
        id: "text",
        header: "Text",
        columnWidth: 250,
        getDisplayValue: (item) => item.text));
    columnDefs.add(MhItemsViewColumnDef<ExampleItem>(
        id: "calculated",
        header: "Calculated",
        columnWidth: 250,
        getDisplayValue: (item) => item.index * item.index));

    // --------------------------------------------
    // - apply settings
    // --------------------------------------------
    final settings = MhItemsViewSettings(
        rowHeight: 25, headerHeight: 30, displayHeader: true);

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          const MhTitleMedium(text: "Some Sample Data"),
          Expanded(
            child: MhItemsView(
                itemsSource: items, columnDefs: columnDefs, settings: settings),
          ),
        ],
      ),
    );
  }
}

class ExampleItem {
  String text;
  int index;

  ExampleItem({required this.text, required this.index});
}
3
likes
140
points
189
downloads

Publisher

verified publishermahop.net

Weekly Downloads

Flutter Widget to display a DataTable, ListView, TreeView (Pro), TreeListView (Pro), with many options, editing, advanced drag and drop support and much more.

Homepage

Topics

#datatable #treeview #listview #gridview #virtualization

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

BSD-3-Clause (license)

Dependencies

collection, flutter, intl, provider

More

Packages that depend on mahop_data_table