table_column.dart 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'package:flutter/widgets.dart';
  2. /// 表格列配置
  3. class TableColumn<T> {
  4. TableColumn({
  5. this.headerText,
  6. this.headerRender,
  7. this.textFormatter,
  8. this.render,
  9. this.textAlign = TextAlign.center,
  10. this.flex = 1,
  11. this.width,
  12. this.minWidth,
  13. this.maxWidth,
  14. this.textFontSize = 15,
  15. }) : assert(() {
  16. if (headerText == null && headerRender == null) {
  17. throw FlutterError(
  18. "`titleText` and `headerRender` cannot both be null.");
  19. }
  20. return true;
  21. }()),
  22. assert(() {
  23. if (textFormatter == null && render == null) {
  24. throw FlutterError(
  25. "`textFormatter` and `render` cannot both be null.");
  26. }
  27. return true;
  28. }());
  29. /// 列头文本
  30. final String? headerText;
  31. /// 列头自定义渲染
  32. final Widget Function()? headerRender;
  33. /// 内容文本格式器
  34. final String Function(T rowData, int rowIndex)? textFormatter;
  35. /// 内容自定义渲染
  36. final Widget Function(T rowData, int rowIndex)? render;
  37. /// 内容文本对齐方式
  38. final TextAlign textAlign;
  39. /// 列宽自适应权重
  40. final int flex;
  41. /// 固定栏宽 -尚未启用
  42. final double? width;
  43. /// 最小列宽 -尚未启用
  44. final double? minWidth;
  45. /// 最大列宽 -尚未启用
  46. final double? maxWidth;
  47. /// 在内容文本格式器的时候改变文字大小
  48. final double? textFontSize;
  49. int get actualFlex => width != null || maxWidth != null ? 0 : flex;
  50. bool get hasWidthLimit =>
  51. width != null || maxWidth != null || minWidth != null;
  52. }