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

Generated by: LCOV version 2.0-1