skeleton method

void skeleton(
  1. dynamic condition, {
  2. int? columns,
  3. int? number,
})

Add skeleton line on rows

Implementation

void skeleton(dynamic condition, {int? columns, int? number}) {
  bool loading = false;

  if (condition is FetchLoading) {
    loading = true;
  }
  if (condition case bool condition) {
    loading = condition;
  }

  if (loading && isNotEmpty || columns != null) {
    // Number of columns in every row
    int columnsFactor = columns ?? first.children.length;

    // Find child with SizedBox type for exclude skeleton
    List<int> sizedBoxIndexes =
        first.children
            .asMap()
            .entries
            .where((entry) => entry.value is SizedBox)
            .map((entry) => entry.key)
            .toList();

    skeleton() => TableRow(
      children: [
        ...Iterable.generate(columnsFactor, (index) {
          if (sizedBoxIndexes.contains(index)) {
            return SizedBox.shrink();
          }
          return SkeletonLine(style: SkeletonLineStyle(borderRadius: BorderRadius.circular(20)));
        }),
      ],
    );

    addAll(Iterable.generate(number ?? 3, (_) => skeleton()));
  }
}