LCOV - code coverage report
Current view: top level - lib/design/form - currency_selector.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 5 53 9.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/_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           0 :   @override
      18           0 :   Widget build(BuildContext context) => LayoutBuilder(builder: (_, constraints) {
      19           0 :         return Padding(
      20             :           padding: const EdgeInsets.all(2),
      21           0 :           child: RowWidget(
      22             :             chunk: const [32, null],
      23             :             indent: 0.0,
      24           0 :             maxWidth: constraints.maxWidth - ThemeHelper.getIndent(),
      25           0 :             alignment: AppDesign.getAlignment<MainAxisAlignment>(),
      26           0 :             children: [
      27           0 :               [
      28           0 :                 item.flag != null ? Text(item.flag!) : ThemeHelper.emptyBox,
      29             :               ],
      30           0 :               [
      31           0 :                 Align(
      32           0 :                   alignment: AppDesign.isRightToLeft() ? Alignment.centerRight : Alignment.centerLeft,
      33           0 :                   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           0 :   @override
      54           0 :   Widget suggest(BuildContext context) => Row(
      55           0 :         mainAxisAlignment: AppDesign.getAlignment<MainAxisAlignment>(),
      56           0 :         children: [
      57           0 :           SizedBox(
      58             :             width: 42,
      59           0 :             child: item.flag != null ? Text(item.flag!) : null,
      60             :           ),
      61           0 :           Expanded(
      62           0 :             child: Column(
      63           0 :               children: [
      64           0 :                 Align(
      65           0 :                   alignment: AppDesign.isRightToLeft() ? Alignment.topRight : Alignment.topLeft,
      66           0 :                   child: TextWrapper(item.code),
      67             :                 ),
      68           0 :                 Align(
      69           0 :                   alignment: AppDesign.isRightToLeft() ? Alignment.topRight : Alignment.topLeft,
      70           0 :                   child: TextWrapper(item.name),
      71             :                 ),
      72             :               ],
      73             :             ),
      74             :           ),
      75           0 :           SizedBox(
      76             :             width: 32,
      77           0 :             child: Center(child: Text(item.symbol)),
      78             :           ),
      79           0 :           SizedBox(
      80             :             width: 12,
      81           0 :             child: InkWell(
      82           0 :               onTap: () => pinItem(context, item),
      83           0 :               child: Icon(
      84           0 :                 CurrencyProvider.isPinned(item) ? Icons.star : Icons.star_border,
      85           0 :                 color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
      86             :               ),
      87             :             ),
      88             :           ),
      89             :         ],
      90             :       );
      91             : 
      92           0 :   @override
      93           0 :   bool match(String search) => '$item'.contains(search);
      94             : 
      95           2 :   @override
      96           6 :   bool equal(val) => val is String ? item.code == val : item.code == (val as BaseListSelectorItem).id;
      97             : 
      98           2 :   @override
      99           2 :   String get id => item.code;
     100             : 
     101           0 :   @override
     102           0 :   String get name => item.name;
     103             : 
     104           4 :   BaseListSelectorItem(this.item) : super(id: '', name: '');
     105             : }
     106             : 
     107             : class BaseCurrencySelector extends ListSelector<BaseListSelectorItem> {
     108           0 :   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           0 :   }) : super(options: CurrencyProvider.getAll().map((e) => BaseListSelectorItem(e)).toList());
     118             : }

Generated by: LCOV version 1.14