component_set 0.1.2 copy "component_set: ^0.1.2" to clipboard
component_set: ^0.1.2 copied to clipboard

Shared Flutter UI widgets and HTTP runtime modules for apps using component_generator.

component_set #

Shared Flutter widgets for apps that use http_method network and code generation: pagination (PaginatedView, PaginationController) and tables (TableContentWidget) that work with the @TableWidget builder.

Setup #

From pub.flutter-io.cn:

dependencies:
  component_set: ^0.1.1

For local development, you can use a path dependency instead (the directory may still be named component on disk):

dependencies:
  component_set:
    path: ../component  # adjust relative to your app

Import the library:

import 'package:component_set/component.dart';

For overlay windows (dialogs, toasts, UIWindowManager, AlertWidget, PositionableWidget) and small helpers (ContextGetter, UpdateMixin) without pulling in pagination/table APIs, use:

import 'package:component_set/component_window.dart';

Ensure your app also depends on http_method (for annotations and build_runner).

PaginatedView and PaginationController #

Use PaginatedView to load paged data and pass rows into a child builder. The generated *Fetch method (from @DataInterface) expects an IPaginationController<TParam>; use PaginationController from this package.

PaginatedView<MyListRequest, MyItem>(
  initialParam: MyListRequest(),
  fetchData: myBizFetch.listSomething,
  builder: (context, data) => MyTableWidget(data: data),
);

PaginationController lives in this package so network.gen.dart can import package:component_set/component.dart and share the same IPaginationController type as the generated network.gen.g.dart part.

@TableWidget code generation #

The @TableWidget annotation comes from package:http_method/http_method.dart. It generates a concrete widget class that extends TableContentWidget<TItem, TParam> and implements genTableHeader / genTableData from your schema fields.

1. Add a part file #

In your page file:

import 'package:flutter/material.dart';
import 'package:http_method/http_method.dart';
import 'package:component_set/component.dart';

part 'my_page.g.dart';

2. Declare a mixin on TableContentWidget #

  • The mixin name must end with Mixin (e.g. _UserTableMixin).
  • It must be on TableContentWidget<YourItem, YourRequest>.
  • Annotate it with @TableWidget and list columns using field names from your list item class (same names as in schema.gen.dart).
@TableWidget(columns: ['id', 'name', 'createdAt'])
mixin _UserTableMixin on TableContentWidget<UserInfo, UserListReq> {
  void onNameTap(BuildContext context, UserInfo item) {
    // optional: tap handler for the `name` column
  }
}

3. Optional customization #

Convention Purpose
on{Field}Tap(BuildContext context, TItem item) Adds onTap on that column’s cell (field name capitalized, e.g. onNameTap for name).
gen{Field}DataCell(BuildContext context, TItem item) Fully custom DataCell for that column.
columns: [] omitted Generator picks non-private fields (and can skip fields via skips).

4. Use the generated class #

The builder emits a public class whose name is derived from the mixin (leading _ stripped, Mixin suffix removed). Example: _UserTableMixinUserTable.

@override
Widget build(BuildContext context) {
  return PaginatedView<UserListReq, UserInfo>(
    initialParam: UserListReq(),
    fetchData: userBizFetch.listUser,
    builder: (context, data) => UserTable(data: data),
  );
}

5. Run the generator #

From your app root:

dart run build_runner build --delete-conflicting-outputs

This produces my_page.g.dart with the UserTable implementation.

Window overlay API (component_window.dart) #

WindowManager, UIWindowManager, AlertWidget, PositionableWidget, and ContextGetter / UpdateMixin live under lib/window/ and lib/simple/. See lib/window/README.md for architecture (root vs shell window managers, showDlg, totast, etc.).

Files in this package #

Export Role
component.dart Full barrel: paging + table + IPaginationController
component_window.dart Window overlays, alerts, ContextGetter, UpdateMixin only
IPaginationController, PaginationController Contract and implementation for generated list fetch methods
PaginatedView Loads data, shows loading/error/empty, hosts PaginationBar
PaginationBar Page/size UI
TableContentWidget Base class for @TableWidget-generated tables
1
likes
130
points
28
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Shared Flutter UI widgets and HTTP runtime modules for apps using component_generator.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, http, http2, path

More

Packages that depend on component_set