google / tuple.dart

A library providing a tuple data structure
https://pub.dev/packages/tuple
BSD 2-Clause "Simplified" License
195 stars 26 forks source link

add length and Type judgment #41

Closed shang1219178163 closed 1 year ago

shang1219178163 commented 1 year ago

add length and Type judgment

devoncarew commented 1 year ago

Thanks for the PR! Can you provide your use case(s) and or examples of how these would be used? Additionally, these changes are logically two separate things, and should be each in their own PRs.

devoncarew commented 1 year ago

And FYI, this package will almost certainly soon go into a maintence mode, as we're about to ship 1st class support for records in Dart.

https://github.com/dart-lang/language/blob/master/accepted/future-releases/records/records-feature-specification.md

https://medium.com/dartlang/dart-3-alpha-f1458fb9d232

shang1219178163 commented 1 year ago

Like this, dynamic use Tuple2, Tuple3, Tuple4, Tuple5, Tuple6, Tuple7; attention to tips variable and items variable;

class _MediaQueryDemoState extends State<MediaQueryDemo> {

  final tips = [
    Tuple3("", “hide keyborad”, “show keyborad"),
    Tuple3("viewInsets", "EdgeInsets.zero", "EdgeInsets(0.0, 0.0, 0.0, 336.0)"),
    Tuple3("viewPadding", "EdgeInsets(0.0, 47.0, 0.0, 34.0)", "EdgeInsets(0.0, 47.0, 0.0, 34.0)"),
    Tuple3("padding", "EdgeInsets(0.0, 47.0, 0.0, 34.0)", "EdgeInsets(0.0, 47.0, 0.0, 0.0)"),
  ];

  final items = [
    Tuple2(“property, “tip”),
    Tuple2("size", "逻辑像素,并不是物理像素,类似于Android中的dp,逻辑像素会在不同大小的手机上显示的大小基本一样,物理像素 = size*devicePixelRatio。"),
    Tuple2("devicePixelRatio", "单位逻辑像素的物理像素数量,即设备像素比。"),
    Tuple2("textScaleFactor", "单位逻辑像素字体像素数,如果设置为1.5则比指定的字体大50%。"),
  ];

…

      body: SafeArea(
        child: CustomScrollView(
          slivers: [
            buildTable(rows: _renderTuples(items: tips)),
            Divider(),
            buildTable(rows: _renderTuples(items: items)),
          ].map((e) => e.toSliverToBoxAdapter()).toList(),
        ),
      )
    );
  }

  Widget buildTable({required List<TableRow> rows}) {
    return Table(
      columnWidths: <int, TableColumnWidth>{
        0: IntrinsicColumnWidth(),
        1: FlexColumnWidth(80),
        2: FlexColumnWidth(80),
      },
      defaultVerticalAlignment: TableCellVerticalAlignment.middle,
      border: TableBorder.all(
        color: Colors.green,
        width: 1,
        style: BorderStyle.solid,
      ),
      children: rows,
    );
  }

  List<TableRow> _renderTuples({List items = const []}) {
    if (items.length == 0 || !isTuple(items[0])) {
      return [];
    }

    return items.map((e) => TableRow(
      children: List.generate(e.length, (index) => Container(
        padding: EdgeInsets.all(8),
        child: Text(e.toList()[index]),
      )).toList(),
    )).toList();
  }

}
devoncarew commented 1 year ago

Thanks for the contribution and the description of use cases in the PR.

However, with the recent release of Dart 3.0 and its support for Records, we plan to move this package into maintenance mode; not take any enhancements to it, and just maintain it from the POV of bug fixes / CI updates to keep it working. There's more detail in the related issue: https://github.com/google/tuple.dart/issues/47; feel free to follow up there with any questions or comments.