LCOV - code coverage report
Current view: top level - lib/design/form - currency_selector.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 44 53 83.0 %
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/_classes/herald/app_locale.dart';
       6             : import 'package:app_finance/_configs/theme_helper.dart';
       7             : import 'package:app_finance/design/form/list_selector.dart';
       8             : import 'package:app_finance/design/form/list_selector_item.dart';
       9             : import 'package:app_finance/design/wrapper/row_widget.dart';
      10             : import 'package:app_finance/design/wrapper/text_wrapper.dart';
      11             : import 'package:flutter/material.dart';
      12             : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      13             : 
      14             : class BaseListSelectorItem extends ListSelectorItem {
      15             :   Currency item;
      16             : 
      17           1 :   @override
      18           2 :   Widget build(BuildContext context) => LayoutBuilder(builder: (_, constraints) {
      19           1 :         return Padding(
      20             :           padding: const EdgeInsets.all(2),
      21           1 :           child: RowWidget(
      22             :             chunk: const [32, null],
      23             :             indent: 0.0,
      24           3 :             maxWidth: constraints.maxWidth - ThemeHelper.getIndent(),
      25           1 :             alignment: AppDesign.getAlignment<MainAxisAlignment>(),
      26           1 :             children: [
      27           1 :               [
      28           3 :                 item.flag != null ? Text(item.flag!) : ThemeHelper.emptyBox,
      29             :               ],
      30           1 :               [
      31           1 :                 Align(
      32           1 :                   alignment: AppDesign.isRightToLeft() ? Alignment.centerRight : Alignment.centerLeft,
      33           5 :                   child: TextWrapper('${item.symbol} | ${item.name} (${item.code})'),
      34             :                 ),
      35             :               ],
      36             :             ],
      37             :           ),
      38             :         );
      39             :       });
      40             : 
      41           0 :   void pinItem(BuildContext context, item) {
      42           0 :     final isPinned = CurrencyProvider.isPinned(item);
      43             :     if (isPinned) {
      44           0 :       CurrencyProvider.unpin(item);
      45             :     } else {
      46           0 :       CurrencyProvider.pin(item);
      47             :     }
      48           0 :     ScaffoldMessenger.of(context).showSnackBar(
      49           0 :       SnackBar(content: Text(isPinned ? AppLocale.labels.orderUnpin : AppLocale.labels.orderPin)),
      50             :     );
      51             :   }
      52             : 
      53           1 :   @override
      54           1 :   Widget suggest(BuildContext context) => Row(
      55           1 :         mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      56           1 :         children: [
      57           1 :           SizedBox(
      58             :             width: 42,
      59           3 :             child: item.flag != null ? Text(item.flag!) : null,
      60             :           ),
      61           1 :           Expanded(
      62           1 :             child: Column(
      63           1 :               children: [
      64           1 :                 Align(
      65           1 :                   alignment: AppDesign.isRightToLeft() ? Alignment.topRight : Alignment.topLeft,
      66           2 :                   child: TextWrapper(item.code),
      67             :                 ),
      68           1 :                 Align(
      69           1 :                   alignment: AppDesign.isRightToLeft() ? Alignment.topRight : Alignment.topLeft,
      70           2 :                   child: TextWrapper(item.name),
      71             :                 ),
      72             :               ],
      73             :             ),
      74             :           ),
      75           1 :           SizedBox(
      76             :             width: 32,
      77           3 :             child: Center(child: Text(item.symbol)),
      78             :           ),
      79           1 :           SizedBox(
      80             :             width: 12,
      81           1 :             child: InkWell(
      82           0 :               onTap: () => pinItem(context, item),
      83           1 :               child: Icon(
      84           2 :                 CurrencyProvider.isPinned(item) ? Icons.star : Icons.star_border,
      85           4 :                 color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
      86             :               ),
      87             :             ),
      88             :           ),
      89             :         ],
      90             :       );
      91             : 
      92           1 :   @override
      93           3 :   bool match(String search) => '$item'.contains(search);
      94             : 
      95           1 :   @override
      96           6 :   bool equal(val) => val is String ? item.code == val : item.code == (val as BaseListSelectorItem).id;
      97             : 
      98           1 :   @override
      99           1 :   String get id => item.code;
     100             : 
     101           0 :   @override
     102           0 :   String get name => item.name;
     103             : 
     104           2 :   BaseListSelectorItem(this.item) : super(id: '', name: '');
     105             : }
     106             : 
     107             : class BaseCurrencySelector extends ListSelector<BaseListSelectorItem> {
     108           1 :   BaseCurrencySelector({
     109             :     super.key,
     110             :     required super.setState,
     111             :     super.value,
     112             :     super.withLabel,
     113             :     super.hintColor,
     114             :     super.hintStyle,
     115             :     super.hintText,
     116             :     super.tooltip,
     117           6 :   }) : super(options: CurrencyProvider.getAll().map((e) => BaseListSelectorItem(e)).toList());
     118             : }

Generated by: LCOV version 1.14