LCOV - code coverage report
Current view: top level - lib/design/wrapper - row_widget.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 34 36 94.4 %
Date: 2024-10-04 11:09:33 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2023 The terCAD team. All rights reserved.
       2             : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3             : 
       4             : import 'package:app_finance/_classes/herald/app_design.dart';
       5             : import 'package:app_finance/_configs/theme_helper.dart';
       6             : import 'package:flutter/material.dart';
       7             : 
       8             : class RowWidget extends StatelessWidget {
       9             :   late final List<double> chunk;
      10             :   final List<List<Widget>> children;
      11             :   final double indent;
      12             :   final double maxWidth;
      13             :   final MainAxisAlignment alignment;
      14             : 
      15           3 :   RowWidget({
      16             :     required List<double?> chunk,
      17             :     required this.children,
      18             :     required this.indent,
      19             :     required this.maxWidth,
      20             :     this.alignment = MainAxisAlignment.spaceBetween,
      21             :     super.key,
      22             :   }) {
      23           3 :     List<double?> scope = [...chunk];
      24           9 :     int restCount = scope.where((e) => e == null).length;
      25             :     double takenWidth = 0;
      26          18 :     double width = maxWidth - indent * (scope.length - 1);
      27           9 :     for (int i = 0; i < scope.length; i++) {
      28           3 :       if (scope[i] == null) {
      29             :         continue;
      30             :       }
      31           3 :       double value = scope[i]!;
      32           6 :       if (value > 0 && value < 1) {
      33           4 :         scope[i] = value * width;
      34           4 :         takenWidth += scope[i]!;
      35             :       } else {
      36           3 :         takenWidth += value;
      37             :       }
      38             :     }
      39           3 :     if (takenWidth > width) {
      40           0 :       double cut = (width - takenWidth) / (scope.length - restCount);
      41           0 :       scope = scope.map((value) => value != null ? value + cut : null).toList();
      42             :       takenWidth = width;
      43             :     }
      44           3 :     if (restCount > 0) {
      45           6 :       double rest = (width - takenWidth) / restCount;
      46           9 :       scope = scope.map((value) => value ?? rest).toList();
      47             :     }
      48           6 :     this.chunk = scope.cast<double>();
      49             :   }
      50             : 
      51           3 :   @override
      52             :   Widget build(BuildContext context) {
      53          12 :     final size = 2 * chunk.length - 1;
      54           3 :     return SizedBox(
      55           3 :       width: maxWidth,
      56           3 :       child: Row(
      57           3 :         crossAxisAlignment: AppDesign.getAlignment(),
      58             :         verticalDirection: VerticalDirection.down,
      59           3 :         mainAxisAlignment: alignment,
      60             :         // mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      61           6 :         children: List<Widget>.generate(size, (index) {
      62           9 :           final idx = AppDesign.getAlignment() == CrossAxisAlignment.start ? index ~/ 2 : (size - index) ~/ 2;
      63           6 :           if (index % 2 == 1) {
      64           6 :             return SizedBox(width: indent);
      65           9 :           } else if (chunk[idx] > 0) {
      66           3 :             return SizedBox(
      67           6 :               width: chunk[idx],
      68           3 :               child: Column(
      69           3 :                 crossAxisAlignment: AppDesign.getAlignment(),
      70           3 :                 mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      71             :                 verticalDirection: VerticalDirection.down,
      72           6 :                 children: children[idx],
      73             :               ),
      74             :             );
      75             :           } else {
      76             :             return ThemeHelper.emptyBox;
      77             :           }
      78             :         }),
      79             :       ),
      80             :     );
      81             :   }
      82             : }

Generated by: LCOV version 1.14