widgets_pack 0.0.5 copy "widgets_pack: ^0.0.5" to clipboard
widgets_pack: ^0.0.5 copied to clipboard

Widgets collection for flutter applications

example/lib/main.dart

import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:widgets_pack/helpers/helpers.dart';
import 'package:widgets_pack/widgets/widgets.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Padding(
            padding: EdgeInsets.all(16),
            child: _Table(),
          ),
        ),
      ),
    );
  }
}

class _Table extends StatefulWidget {
  const _Table();

  @override
  State<_Table> createState() => _TableState();
}

class User extends Equatable {
  final int id;
  final String name;
  final String email;

  const User({
    required this.id,
    required this.name,
    required this.email,
  });

  @override
  List<Object?> get props => [id, name, email];

  @override
  String toString() {
    return 'User{id: $id, name: $name, email: $email}';
  }
}

class _TableState extends State<_Table> {
  late final tableController = TableController<User>(
    loadFn: (page, pageSize) async {
      return Future.delayed(
        const Duration(seconds: 3),
        () {
          return List.generate(
            pageSize,
            (index) => User(
              id: index * page + index,
              name: 'User $index',
              email: '$index@gmail.com',
            ),
          );
        },
      );
    },
  );

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        AppTable<User>(
          headerAction: AppButtonConfig.text(
            'Add',
            type: AppButtonType.tonal,
            onPressed: () {},
          ),
          onRowTap: print,
          controller: tableController,
          actions: (items) => [
            const TableAction(
              label: 'View',
              icon: Icon(Icons.remove_red_eye),
            ),
            TableActionDivider(),
            TableAction(
              label: 'Delete',
              icon: const Icon(
                Icons.delete,
                color: Colors.red,
              ),
              onPressed: () {
                tableController.reloadCurrentPage();
              },
            ),
          ],
          columns: [
            TextColumn(
              label: const Text('ID'),
              width: 50,
              value: (user) => user.id.toString(),
              fixed: true,
            ),
            TextColumn(
              label: const Text('Name'),
              value: (user) => user.name,
              width: 150,
              fixed: true,
            ),
            TextColumn(
              label: const Text('Email'),
              value: (user) => user.email,
              width: 150,
            ),
            TextColumn(
              label: const Text('Email'),
              value: (user) => user.email,
            ),
          ],
        ),
      ],
    );
  }
}
1
likes
0
pub points
67%
popularity

Publisher

unverified uploader

Widgets collection for flutter applications

License

unknown (license)

Dependencies

equatable, extensions_pack, flutter, flutter_spinkit, rxdart

More

Packages that depend on widgets_pack