dc_datatable 1.0.1

SDKflutter
Platformandroidioswindowslinuxmacosweb

Package para Widget de Datatable com paginação

ScreenShot

screenshot

Usage

NOTE:* don't put the widgets into any unconstrained parents with infinite width or height (e.g. scrollables such as SingleChildScrollView, Column etc.). The widgets are designed to stretch and fill all available space within parent and have a number of own scrollables inside to address fixed rows/columns feature. Putting it inside unconstrained parent break widgets.

  1. Add reference to pubspec.yaml.

  2. Import:

import 'package:dc_datatable/dc_datatable.dart';
  1. Code:
import 'package:flutter/material.dart';
import 'package:dc_datatable/dc_datatable.dart';



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

class MyApp extends StatelessWidget {
  
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example DcDataTable',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Example DcDataTable'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int activePage = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            DcDatatableWidget<List<ModelExample>>(
              futureData: _onFutureData(),
              columns: const [
                DataColumn(label: Text('ID')),
                DataColumn(label: Text('Name')),
                DataColumn(label: Text('Description')),
              ],
              onPageChange: (int page) {
                setState(() {
                  activePage = page;
                  _onFutureData();
                });
              },
            )
          ],
        ),
      ),
    );
  }

  Future<DcDataResponse> _onFutureData() async {
    debugPrint("Executando on update $activePage");
    Future.delayed(const Duration(seconds: 4));

    List<ModelExample> dados = List.generate(10, (i) {
      return ModelExample(
          id: i,
          name: "Name $activePage",
          description: "Description $activePage");
    });

    List<DataRow> rows = List.generate(10, (index) {
      ModelExample model = dados[index];
      return DataRow(cells: <DataCell>[
        DataCell(Text(model.id.toString())),
        DataCell(Text(model.name)),
        DataCell(Text(model.description)),
      ]);
    });

    return DcDataResponse(110, dados, rows);
  }
}


class ModelExample {
  final int id;
  final String name;
  final String description;

  ModelExample({
    required this.id,
    required this.name,
    required this.description,
  });

}