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
@TableWidgetand listcolumnsusing field names from your list item class (same names as inschema.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: _UserTableMixin → UserTable.
@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 |
Libraries
- component
- Shared widgets: paginated lists and TableContentWidget for use with
http_method@TableWidgetcode generation. - component_set
- Shared widgets and HTTP runtime primitives used by generated API code.
- component_window
- Overlay window management, alerts, and small helpers (
ContextGetter, UpdateMixin). Does not export paging or TableContentWidget — usecomponent.dartfor those. - http/function
- http/http1_client
- http/http2_client
- http/http_base
- http/http_buffer
- http/http_client_base
- http/log
- http/multi_part_parameter
- http/parameter
- http1_client
- http2_client
- paging/paginated_view
- paging/pagination_bar
- paging/pagination_controller
- simple/simple_widget
- simple/update
- table_content_widget
- window/alert
- window/positionable_widget
- window/window_manager