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:12:13 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           1 :   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           1 :     List<double?> scope = [...chunk];
      24           3 :     int restCount = scope.where((e) => e == null).length;
      25             :     double takenWidth = 0;
      26           6 :     double width = maxWidth - indent * (scope.length - 1);
      27           3 :     for (int i = 0; i < scope.length; i++) {
      28           1 :       if (scope[i] == null) {
      29             :         continue;
      30             :       }
      31           1 :       double value = scope[i]!;
      32           2 :       if (value > 0 && value < 1) {
      33           2 :         scope[i] = value * width;
      34           2 :         takenWidth += scope[i]!;
      35             :       } else {
      36           1 :         takenWidth += value;
      37             :       }
      38             :     }
      39           1 :     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           1 :     if (restCount > 0) {
      45           2 :       double rest = (width - takenWidth) / restCount;
      46           3 :       scope = scope.map((value) => value ?? rest).toList();
      47             :     }
      48           2 :     this.chunk = scope.cast<double>();
      49             :   }
      50             : 
      51           1 :   @override
      52             :   Widget build(BuildContext context) {
      53           4 :     final size = 2 * chunk.length - 1;
      54           1 :     return SizedBox(
      55           1 :       width: maxWidth,
      56           1 :       child: Row(
      57           1 :         crossAxisAlignment: AppDesign.getAlignment(),
      58             :         verticalDirection: VerticalDirection.down,
      59           1 :         mainAxisAlignment: alignment,
      60             :         // mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      61           2 :         children: List<Widget>.generate(size, (index) {
      62           3 :           final idx = AppDesign.getAlignment() == CrossAxisAlignment.start ? index ~/ 2 : (size - index) ~/ 2;
      63           2 :           if (index % 2 == 1) {
      64           2 :             return SizedBox(width: indent);
      65           3 :           } else if (chunk[idx] > 0) {
      66           1 :             return SizedBox(
      67           2 :               width: chunk[idx],
      68           1 :               child: Column(
      69           1 :                 crossAxisAlignment: AppDesign.getAlignment(),
      70           1 :                 mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      71             :                 verticalDirection: VerticalDirection.down,
      72           2 :                 children: children[idx],
      73             :               ),
      74             :             );
      75             :           } else {
      76             :             return ThemeHelper.emptyBox;
      77             :           }
      78             :         }),
      79             :       ),
      80             :     );
      81             :   }
      82             : }

Generated by: LCOV version 1.14