/* * This file is part of Stack Wallet. * * Copyright (c) 2023 Cypher Stack * All Rights Reserved. * The code is distributed under GPLv3 license, see LICENSE file for details. * Generated by Cypher Stack on 2023-05-26 * */ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import '../providers/providers.dart'; import '../app_config.dart'; import '../themes/coin_icon_provider.dart'; import '../themes/stack_colors.dart'; import '../utilities/constants.dart'; import '../utilities/text_styles.dart'; import '../wallets/crypto_currency/crypto_currency.dart'; import 'background.dart'; import 'custom_buttons/app_bar_icon_button.dart'; import 'rounded_white_container.dart'; /* * This widget is used to choose a coin from a list of coins. * @param title: The title of the page. * @param coinAdditional: Additional text to be displayed after the coin name. * @param nextRouteName: The name of the route to be pushed when a coin is selected. * @return A widget that displays a list of coins. */ class ChooseCoinView extends ConsumerStatefulWidget { const ChooseCoinView({ super.key, required this.title, required this.coinAdditional, required this.nextRouteName, }); static const String routeName = "/chooseCoin"; final String title; final String coinAdditional; final String nextRouteName; @override ConsumerState createState() => _ChooseCoinViewState(); } class _ChooseCoinViewState extends ConsumerState { List _coins = [...AppConfig.coins]; @override void initState() { _coins = _coins.toList(); _coins.removeWhere( (e) => e.identifier == Firo(CryptoCurrencyNetwork.test).identifier, ); super.initState(); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { final bool showTestNet = ref.watch( prefsChangeNotifierProvider.select((value) => value.showTestNetCoins), ); final List coins = showTestNet ? _coins : _coins .where( (e) => e.network == CryptoCurrencyNetwork.main, ) .toList(); return Background( child: Scaffold( backgroundColor: Theme.of(context).extension()!.background, appBar: AppBar( leading: AppBarBackButton( onPressed: () { Navigator.of(context).pop(); }, ), title: Text( widget.title, style: STextStyles.navBarTitle(context), ), ), body: Padding( padding: const EdgeInsets.only( top: 12, left: 12, right: 12, ), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ...coins.map( (coin) { return Padding( padding: const EdgeInsets.all(4), child: RoundedWhiteContainer( padding: const EdgeInsets.all(0), child: RawMaterialButton( // splashColor: Theme.of(context).extension()!.highlight, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular( Constants.size.circularBorderRadius, ), ), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onPressed: () { Navigator.of(context).pushNamed( widget.nextRouteName, arguments: coin, ); }, child: Padding( padding: const EdgeInsets.all(12), child: Row( children: [ SvgPicture.file( File( ref.watch(coinIconProvider(coin)), ), width: 24, height: 24, ), const SizedBox( width: 12, ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "${coin.prettyName} ${widget.coinAdditional}", style: STextStyles.titleBold12(context), ), ], ) ], ), ), ), ), ); }, ), ], ), ), ), ), ); } }