pivot_table 0.0.1 copy "pivot_table: ^0.0.1" to clipboard
pivot_table: ^0.0.1 copied to clipboard

A Flutter package providing a dynamic and flexible pivot table. use only json string to create pivot table.

Pivot Table for Flutter #

A Flutter package for creating customizable pivot tables with support for data aggregation, sorting, filtering, and grouping. This package is ideal for displaying and analyzing large datasets in a structured way.

[Pivot Table Demo]

Features #

  • Dynamic data pivoting based on rows and columns
  • can use with string of json array
  • Support for aggregation functions like sum, count.
  • Customizable cell renderers and formatting

Getting Started #

Installation #

Add the following to your pubspec.yaml file:

dependencies:
  pivot_table:
    git:
      url: https://github.com/BoyPhanna/flutter_pivot_table.git

Example Code #

Add the following to your main.dart file:

import 'package:flutter/material.dart';
import 'package:pivot_table/aggregator_functions.dart';
import 'package:pivot_table/pivot_table.dart';

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 MaterialApp(
      title: 'Pivot Table',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Home Page Pivot Table'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String jsonString = '''
                             [
                              {"name": "Alice", "age": 30, "gender": "Female", "region": "North", "sales": 150, "cost": 100, "profit": 50, "products": "Electronics", "quarter": "Q1"},
                              {"name": "Bob", "age": 25, "gender": "Male", "region": "South", "sales": 200, "cost": 120, "profit": 80, "products": "Clothing", "quarter": "Q2"},
                              {"name": "Charlie", "age": 30, "gender": "Male", "region": "North", "sales": 100, "cost": 70, "profit": 30, "products": "Electronics", "quarter": "Q1"},
                              {"name": "David", "age": 25, "gender": "Male", "region": "West", "sales": 120, "cost": 80, "profit": 40, "products": "Furniture", "quarter": "Q3"},
                              {"name": "Eve", "age": 30, "gender": "Female", "region": "South", "sales": 300, "cost": 180, "profit": 120, "products": "Clothing", "quarter": "Q2"},
                              {"name": "Fay", "age": 25, "gender": "Female", "region": "West", "sales": 180, "cost": 100, "profit": 80, "products": "Electronics", "quarter": "Q3"},
                              {"name": "Grace", "age": 25, "gender": "Female", "region": "South", "sales": 170, "cost": 90, "profit": 80, "products": "Furniture", "quarter": "Q1"},
                              {"name": "Henry", "age": 28, "gender": "Male", "region": "East", "sales": 250, "cost": 150, "profit": 100, "products": "Groceries", "quarter": "Q2"},
                              {"name": "Isabella", "age": 27, "gender": "Female", "region": "West", "sales": 190, "cost": 110, "profit": 80, "products": "Clothing", "quarter": "Q3"},
                              {"name": "Jack", "age": 35, "gender": "Male", "region": "North", "sales": 300, "cost": 200, "profit": 100, "products": "Electronics", "quarter": "Q4"},
                              {"name": "Kathy", "age": 32, "gender": "Female", "region": "South", "sales": 120, "cost": 70, "profit": 50, "products": "Furniture", "quarter": "Q4"},
                              {"name": "Leo", "age": 29, "gender": "Male", "region": "East", "sales": 220, "cost": 130, "profit": 90, "products": "Groceries", "quarter": "Q1"},
                              {"name": "Mona", "age": 26, "gender": "Female", "region": "West", "sales": 160, "cost": 90, "profit": 70, "products": "Electronics", "quarter": "Q2"}
      ]
''';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(children: [
          PivotTable(
            marginname: 'Total Profit',
            jsonString: jsonString,
            rowFields: ["name", "region"],
            columnFields: ["products", "quarter"],
            valueFields: ['profit'],
            valueAggregator: AggregatorFunctions.sumAggregator,
          ),
        ]),
      ),
    );
  }
}

11
likes
0
points
46
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package providing a dynamic and flexible pivot table. use only json string to create pivot table.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on pivot_table