mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
Merge branch 'staging' into docs
This commit is contained in:
commit
6bed5e3e03
18 changed files with 1015 additions and 175 deletions
|
@ -9,7 +9,6 @@ import 'package:stackwallet/providers/global/secure_store_provider.dart';
|
|||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/biometrics.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
|
@ -139,6 +138,8 @@ class _CreatePinViewState extends ConsumerState<CreatePinView> {
|
|||
.background,
|
||||
counterText: "",
|
||||
),
|
||||
isRandom:
|
||||
ref.read(prefsChangeNotifierProvider).randomizePIN,
|
||||
submittedFieldDecoration: _pinPutDecoration.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
|
@ -221,6 +222,8 @@ class _CreatePinViewState extends ConsumerState<CreatePinView> {
|
|||
),
|
||||
selectedFieldDecoration: _pinPutDecoration,
|
||||
followingFieldDecoration: _pinPutDecoration,
|
||||
isRandom:
|
||||
ref.read(prefsChangeNotifierProvider).randomizePIN,
|
||||
onSubmit: (String pin) async {
|
||||
// _onSubmitCount++;
|
||||
// if (_onSubmitCount - _onSubmitFailCount > 1) return;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
@ -21,8 +20,8 @@ import 'package:stackwallet/utilities/text_styles.dart';
|
|||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/widgets/background.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
||||
import 'package:stackwallet/widgets/custom_pin_put/custom_pin_put.dart';
|
||||
import 'package:stackwallet/widgets/custom_pin_put/pin_keyboard.dart';
|
||||
import 'package:stackwallet/widgets/shake/shake.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
|
@ -93,7 +92,7 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
|
|||
|
||||
final manager =
|
||||
ref.read(walletsChangeNotifierProvider).getManager(walletId);
|
||||
if (manager.coin == Coin.monero || manager.coin == Coin.wownero) {
|
||||
if (manager.coin == Coin.monero) {
|
||||
await showLoading(
|
||||
opaqueBG: true,
|
||||
whileFuture: manager.initializeExisting(),
|
||||
|
@ -229,6 +228,26 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
|
|||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// check prefs and hide if user has biometrics toggle off?
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 40.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
if (ref.read(prefsChangeNotifierProvider).useBiometrics ==
|
||||
true)
|
||||
CustomTextButton(
|
||||
text: "Use biometrics",
|
||||
onTap: () async {
|
||||
await _checkUseBiometrics();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 55,
|
||||
),
|
||||
Shake(
|
||||
animationDuration: const Duration(milliseconds: 700),
|
||||
animationRange: 12,
|
||||
|
@ -247,16 +266,12 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
|
|||
height: 52,
|
||||
),
|
||||
CustomPinPut(
|
||||
customKey: CustomKey(
|
||||
semanticsLabel: Platform.isIOS
|
||||
? "Face ID Button. Checks Face ID."
|
||||
: "Fingerprint Button. Checks Fingerprint."
|
||||
,
|
||||
onPressed: _checkUseBiometrics,
|
||||
iconAssetName: Platform.isIOS
|
||||
? Assets.svg.faceId
|
||||
: Assets.svg.fingerprint,
|
||||
),
|
||||
// customKey: CustomKey(
|
||||
// onPressed: _checkUseBiometrics,
|
||||
// iconAssetName: Platform.isIOS
|
||||
// ? Assets.svg.faceId
|
||||
// : Assets.svg.fingerprint,
|
||||
// ),
|
||||
fieldsCount: Constants.pinLength,
|
||||
eachFieldHeight: 12,
|
||||
eachFieldWidth: 12,
|
||||
|
@ -292,6 +307,9 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
|
|||
),
|
||||
selectedFieldDecoration: _pinPutDecoration,
|
||||
followingFieldDecoration: _pinPutDecoration,
|
||||
isRandom: ref
|
||||
.read(prefsChangeNotifierProvider)
|
||||
.randomizePIN,
|
||||
onSubmit: (String pin) async {
|
||||
_attempts++;
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/pages/settings_views/global_settings_view/security_views/security_view.dart';
|
||||
import 'package:stackwallet/providers/global/prefs_provider.dart';
|
||||
import 'package:stackwallet/providers/global/secure_store_provider.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
|
@ -123,6 +123,8 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
|
|||
.background,
|
||||
counterText: "",
|
||||
),
|
||||
isRandom:
|
||||
ref.read(prefsChangeNotifierProvider).randomizePIN,
|
||||
submittedFieldDecoration: _pinPutDecoration.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
|
@ -188,6 +190,8 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
|
|||
.background,
|
||||
counterText: "",
|
||||
),
|
||||
isRandom:
|
||||
ref.read(prefsChangeNotifierProvider).randomizePIN,
|
||||
submittedFieldDecoration: _pinPutDecoration.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
|
|
|
@ -146,6 +146,53 @@ class SecurityView extends StatelessWidget {
|
|||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
RoundedWhiteContainer(
|
||||
child: Consumer(
|
||||
builder: (_, ref, __) {
|
||||
return RawMaterialButton(
|
||||
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
Constants.size.circularBorderRadius,
|
||||
),
|
||||
),
|
||||
onPressed: null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"Randomize PIN Pad",
|
||||
style: STextStyles.titleBold12(context),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
width: 40,
|
||||
child: DraggableSwitchButton(
|
||||
isOn: ref.watch(
|
||||
prefsChangeNotifierProvider
|
||||
.select((value) => value.randomizePIN),
|
||||
),
|
||||
onValueChanged: (newValue) {
|
||||
ref
|
||||
.read(prefsChangeNotifierProvider)
|
||||
.randomizePIN = newValue;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -14,6 +14,8 @@ import 'package:stackwallet/utilities/show_loading.dart';
|
|||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||
import 'package:stackwallet/widgets/dialogs/basic_dialog.dart';
|
||||
import 'package:stackwallet/widgets/icon_widgets/eth_token_icon.dart';
|
||||
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
||||
|
||||
|
@ -36,6 +38,36 @@ class _MyTokenSelectItemState extends ConsumerState<MyTokenSelectItem> {
|
|||
|
||||
late final CachedEthTokenBalance cachedBalance;
|
||||
|
||||
Future<bool> _loadTokenWallet(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
) async {
|
||||
try {
|
||||
await ref.read(tokenServiceProvider)!.initialize();
|
||||
return true;
|
||||
} catch (_) {
|
||||
await showDialog<void>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => BasicDialog(
|
||||
title: "Failed to load token data",
|
||||
desktopHeight: double.infinity,
|
||||
desktopWidth: 450,
|
||||
rightButton: PrimaryButton(
|
||||
label: "OK",
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
if (!isDesktop) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void _onPressed() async {
|
||||
ref.read(tokenServiceStateProvider.state).state = EthTokenWallet(
|
||||
token: widget.token,
|
||||
|
@ -49,13 +81,17 @@ class _MyTokenSelectItemState extends ConsumerState<MyTokenSelectItem> {
|
|||
),
|
||||
);
|
||||
|
||||
await showLoading<void>(
|
||||
whileFuture: ref.read(tokenServiceProvider)!.initialize(),
|
||||
final success = await showLoading<bool>(
|
||||
whileFuture: _loadTokenWallet(context, ref),
|
||||
context: context,
|
||||
isDesktop: isDesktop,
|
||||
message: "Loading ${widget.token.name}",
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
await Navigator.of(context).pushNamed(
|
||||
isDesktop ? DesktopTokenView.routeName : TokenView.routeName,
|
||||
|
|
|
@ -53,6 +53,7 @@ import 'package:stackwallet/widgets/conditional_parent.dart';
|
|||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
||||
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
|
||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/buy_nav_icon.dart';
|
||||
|
@ -420,6 +421,33 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
|||
eventBus: null,
|
||||
textColor:
|
||||
Theme.of(context).extension<StackColors>()!.textDark,
|
||||
actionButton: SecondaryButton(
|
||||
label: "Cancel",
|
||||
onPressed: () async {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => StackDialog(
|
||||
title: "Warning!",
|
||||
message: "Skipping this process can completely"
|
||||
" break your wallet. It is only meant to be done in"
|
||||
" emergency situations where the migration fails"
|
||||
" and will not let you continue. Still skip?",
|
||||
leftButton: SecondaryButton(
|
||||
label: "Cancel",
|
||||
onPressed:
|
||||
Navigator.of(context, rootNavigator: true).pop,
|
||||
),
|
||||
rightButton: SecondaryButton(
|
||||
label: "Ok",
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
setState(() => _rescanningOnOpen = false);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
@ -793,7 +821,6 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
|||
label: "Receive",
|
||||
icon: const ReceiveNavIcon(),
|
||||
onTap: () {
|
||||
final coin = ref.read(managerProvider).coin;
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
Navigator.of(context).pushNamed(
|
||||
|
|
|
@ -31,7 +31,11 @@ import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
|||
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
||||
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
|
||||
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||
import 'package:stackwallet/widgets/hover_text_field.dart';
|
||||
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
||||
|
||||
|
@ -150,6 +154,83 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
subMessage: "This only needs to run once per wallet",
|
||||
eventBus: null,
|
||||
textColor: Theme.of(context).extension<StackColors>()!.textDark,
|
||||
actionButton: SecondaryButton(
|
||||
label: "Skip",
|
||||
buttonHeight: ButtonHeight.l,
|
||||
onPressed: () async {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => DesktopDialog(
|
||||
maxWidth: 500,
|
||||
maxHeight: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 32),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"Warning!",
|
||||
style: STextStyles.desktopH3(context),
|
||||
),
|
||||
const DesktopDialogCloseButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 32),
|
||||
child: Text(
|
||||
"Skipping this process can completely"
|
||||
" break your wallet. It is only meant to be done in"
|
||||
" emergency situations where the migration fails"
|
||||
" and will not let you continue. Still skip?",
|
||||
style: STextStyles.desktopTextSmall(context),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 32,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SecondaryButton(
|
||||
label: "Cancel",
|
||||
buttonHeight: ButtonHeight.l,
|
||||
onPressed: Navigator.of(context,
|
||||
rootNavigator: true)
|
||||
.pop,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: "Ok",
|
||||
buttonHeight: ButtonHeight.l,
|
||||
onPressed: () {
|
||||
Navigator.of(context,
|
||||
rootNavigator: true)
|
||||
.pop();
|
||||
setState(
|
||||
() => _rescanningOnOpen = false);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
|
|
@ -1949,8 +1949,6 @@ class BitcoinCashWallet extends CoinServiceAPI
|
|||
|
||||
List<Map<String, dynamic>> allTransactions = [];
|
||||
|
||||
final currentHeight = await chainHeight;
|
||||
|
||||
for (final txHash in allTxHashes) {
|
||||
final storedTx = await db
|
||||
.getTransactions(walletId)
|
||||
|
@ -1958,7 +1956,9 @@ class BitcoinCashWallet extends CoinServiceAPI
|
|||
.txidEqualTo(txHash["tx_hash"] as String)
|
||||
.findFirst();
|
||||
|
||||
if (storedTx == null || storedTx.address.value == null
|
||||
if (storedTx == null ||
|
||||
storedTx.address.value == null ||
|
||||
storedTx.height == null
|
||||
// zero conf messes this up
|
||||
// !storedTx.isConfirmed(currentHeight, MINIMUM_CONFIRMATIONS)
|
||||
) {
|
||||
|
|
|
@ -253,6 +253,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
);
|
||||
_credentials = web3dart.EthPrivateKey.fromHex(privateKey);
|
||||
|
||||
try {
|
||||
_deployedContract = web3dart.DeployedContract(
|
||||
ContractAbiExtensions.fromJsonList(
|
||||
jsonList: tokenContract.abi!,
|
||||
|
@ -260,6 +261,9 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
),
|
||||
contractAddress,
|
||||
);
|
||||
} catch (_) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
try {
|
||||
_sendFunction = _deployedContract.function('transfer');
|
||||
|
@ -328,6 +332,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
//====================================================================
|
||||
}
|
||||
|
||||
try {
|
||||
_deployedContract = web3dart.DeployedContract(
|
||||
ContractAbiExtensions.fromJsonList(
|
||||
jsonList: tokenContract.abi!,
|
||||
|
@ -335,6 +340,9 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
),
|
||||
contractAddress,
|
||||
);
|
||||
} catch (_) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
_sendFunction = _deployedContract.function('transfer');
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:web3dart/web3dart.dart';
|
||||
|
||||
extension ContractAbiExtensions on ContractAbi {
|
||||
|
@ -7,10 +8,12 @@ extension ContractAbiExtensions on ContractAbi {
|
|||
required String name,
|
||||
required String jsonList,
|
||||
}) {
|
||||
try {
|
||||
final List<ContractFunction> functions = [];
|
||||
final List<ContractEvent> events = [];
|
||||
|
||||
final list = List<Map<String, dynamic>>.from(jsonDecode(jsonList) as List);
|
||||
final list =
|
||||
List<Map<String, dynamic>>.from(jsonDecode(jsonList) as List);
|
||||
|
||||
for (final json in list) {
|
||||
final type = json["type"] as String;
|
||||
|
@ -20,6 +23,7 @@ extension ContractAbiExtensions on ContractAbi {
|
|||
final anonymous = json["anonymous"] as bool? ?? false;
|
||||
final List<EventComponent<dynamic>> components = [];
|
||||
|
||||
if (json["inputs"] is List) {
|
||||
for (final input in json["inputs"] as List) {
|
||||
components.add(
|
||||
EventComponent(
|
||||
|
@ -28,6 +32,7 @@ extension ContractAbiExtensions on ContractAbi {
|
|||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
events.add(ContractEvent(anonymous, name, components));
|
||||
} else {
|
||||
|
@ -51,6 +56,13 @@ extension ContractAbiExtensions on ContractAbi {
|
|||
}
|
||||
|
||||
return ContractAbi(name, functions, events);
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
"Failed to parse ABI for $name: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static const Map<String, ContractFunctionType> _functionTypeNames = {
|
||||
|
|
|
@ -19,6 +19,7 @@ class Prefs extends ChangeNotifier {
|
|||
if (!_initialized) {
|
||||
_currency = await _getPreferredCurrency();
|
||||
// _exchangeRateType = await _getExchangeRateType();
|
||||
_randomizePIN = await _getRandomizePIN();
|
||||
_useBiometrics = await _getUseBiometrics();
|
||||
_hasPin = await _getHasPin();
|
||||
_language = await _getPreferredLanguage();
|
||||
|
@ -295,6 +296,27 @@ class Prefs extends ChangeNotifier {
|
|||
// }
|
||||
// }
|
||||
|
||||
// randomize PIN
|
||||
|
||||
bool _randomizePIN = false;
|
||||
|
||||
bool get randomizePIN => _randomizePIN;
|
||||
|
||||
set randomizePIN(bool randomizePIN) {
|
||||
if (_randomizePIN != randomizePIN) {
|
||||
DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNamePrefs, key: "randomizePIN", value: randomizePIN);
|
||||
_randomizePIN = randomizePIN;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _getRandomizePIN() async {
|
||||
return await DB.instance.get<dynamic>(
|
||||
boxName: DB.boxNamePrefs, key: "randomizePIN") as bool? ??
|
||||
false;
|
||||
}
|
||||
|
||||
// use biometrics
|
||||
|
||||
bool _useBiometrics = false;
|
||||
|
|
|
@ -5,6 +5,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||
|
||||
class CustomLoadingOverlay extends ConsumerStatefulWidget {
|
||||
|
@ -14,12 +16,14 @@ class CustomLoadingOverlay extends ConsumerStatefulWidget {
|
|||
this.subMessage,
|
||||
required this.eventBus,
|
||||
this.textColor,
|
||||
this.actionButton,
|
||||
}) : super(key: key);
|
||||
|
||||
final String message;
|
||||
final String? subMessage;
|
||||
final EventBus? eventBus;
|
||||
final Color? textColor;
|
||||
final Widget? actionButton;
|
||||
|
||||
@override
|
||||
ConsumerState<CustomLoadingOverlay> createState() =>
|
||||
|
@ -30,6 +34,7 @@ class _CustomLoadingOverlayState extends ConsumerState<CustomLoadingOverlay> {
|
|||
double _percent = 0;
|
||||
|
||||
late final StreamSubscription<double>? subscription;
|
||||
final bool isDesktop = Util.isDesktop;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -49,14 +54,45 @@ class _CustomLoadingOverlayState extends ConsumerState<CustomLoadingOverlay> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: ConditionalParent(
|
||||
condition: widget.actionButton != null,
|
||||
builder: (child) => Stack(
|
||||
children: [
|
||||
child,
|
||||
if (isDesktop)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SizedBox(
|
||||
width: 100,
|
||||
child: widget.actionButton!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!isDesktop)
|
||||
Positioned(
|
||||
bottom: 1,
|
||||
left: 0,
|
||||
right: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: widget.actionButton!),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
widget.message,
|
||||
|
@ -97,10 +133,6 @@ class _CustomLoadingOverlayState extends ConsumerState<CustomLoadingOverlay> {
|
|||
.extension<StackColors>()!
|
||||
.loadingOverlayTextColor,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 64,
|
||||
|
@ -111,6 +143,8 @@ class _CustomLoadingOverlayState extends ConsumerState<CustomLoadingOverlay> {
|
|||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ class CustomPinPut extends StatefulWidget {
|
|||
const CustomPinPut({
|
||||
Key? key,
|
||||
required this.fieldsCount,
|
||||
required this.isRandom,
|
||||
this.height,
|
||||
this.width,
|
||||
this.onSubmit,
|
||||
|
@ -60,6 +61,8 @@ class CustomPinPut extends StatefulWidget {
|
|||
|
||||
final CustomKey? customKey;
|
||||
|
||||
final bool isRandom;
|
||||
|
||||
/// Displayed fields count. PIN code length.
|
||||
final int fieldsCount;
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ class CustomPinPutState extends State<CustomPinPut>
|
|||
} catch (e) {
|
||||
_textControllerValue = ValueNotifier(_controller.value.text);
|
||||
}
|
||||
if (pin.length == widget.fieldsCount) {
|
||||
widget.onSubmit?.call(pin);
|
||||
}
|
||||
// if (pin.length == widget.fieldsCount) {
|
||||
// widget.onSubmit?.call(pin);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,9 @@ class CustomPinPutState extends State<CustomPinPut>
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// final bool randomize = ref
|
||||
// .read(prefsChangeNotifierProvider)
|
||||
// .randomizePIN;
|
||||
return SizedBox(
|
||||
width: widget.width,
|
||||
height: widget.height,
|
||||
|
@ -69,6 +72,7 @@ class CustomPinPutState extends State<CustomPinPut>
|
|||
),
|
||||
Center(
|
||||
child: PinKeyboard(
|
||||
isRandom: widget.isRandom,
|
||||
customKey: widget.customKey,
|
||||
onNumberKeyPressed: (number) {
|
||||
if (_controller.text.length < widget.fieldsCount) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -247,8 +248,169 @@ class CustomKey extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class PinKeyboard extends StatelessWidget {
|
||||
class PinKeyboard extends ConsumerWidget {
|
||||
const PinKeyboard({
|
||||
Key? key,
|
||||
required this.onNumberKeyPressed,
|
||||
required this.onBackPressed,
|
||||
required this.onSubmitPressed,
|
||||
required this.isRandom,
|
||||
this.backgroundColor,
|
||||
this.width = 264,
|
||||
this.height = 360,
|
||||
this.customKey,
|
||||
}) : super(key: key);
|
||||
|
||||
final ValueSetter<String> onNumberKeyPressed;
|
||||
final VoidCallback onBackPressed;
|
||||
final VoidCallback onSubmitPressed;
|
||||
final Color? backgroundColor;
|
||||
final double? width;
|
||||
final double? height;
|
||||
final CustomKey? customKey;
|
||||
final bool isRandom;
|
||||
|
||||
void _backHandler() {
|
||||
onBackPressed.call();
|
||||
}
|
||||
|
||||
void _submitHandler() {
|
||||
onSubmitPressed.call();
|
||||
}
|
||||
|
||||
void _numberHandler(String number) {
|
||||
onNumberKeyPressed.call(number);
|
||||
HapticFeedback.lightImpact();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final list = [
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"0",
|
||||
];
|
||||
|
||||
// final isRandom = ref.read(prefsChangeNotifierProvider).randomizePIN;
|
||||
|
||||
if (isRandom) list.shuffle();
|
||||
|
||||
return Container(
|
||||
width: width,
|
||||
height: height,
|
||||
color: backgroundColor ?? Colors.transparent,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
NumberKey(
|
||||
number: list[0],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[1],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[2],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
NumberKey(
|
||||
number: list[3],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[4],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[5],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
NumberKey(
|
||||
number: list[6],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[7],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[8],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
BackspaceKey(
|
||||
onPressed: _backHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[9],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
SubmitKey(
|
||||
onPressed: _submitHandler,
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RandomKeyboard extends StatelessWidget {
|
||||
const RandomKeyboard({
|
||||
Key? key,
|
||||
required this.onNumberKeyPressed,
|
||||
required this.onBackPressed,
|
||||
|
@ -278,10 +440,24 @@ class PinKeyboard extends StatelessWidget {
|
|||
void _numberHandler(String number) {
|
||||
onNumberKeyPressed.call(number);
|
||||
HapticFeedback.lightImpact();
|
||||
debugPrint("NUMBER: $number");
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final list = [
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"0",
|
||||
];
|
||||
list.shuffle();
|
||||
return Container(
|
||||
width: width,
|
||||
height: height,
|
||||
|
@ -291,21 +467,21 @@ class PinKeyboard extends StatelessWidget {
|
|||
Row(
|
||||
children: [
|
||||
NumberKey(
|
||||
number: "1",
|
||||
number: list[0],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: "2",
|
||||
number: list[1],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: "3",
|
||||
number: list[2],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
],
|
||||
|
@ -316,21 +492,21 @@ class PinKeyboard extends StatelessWidget {
|
|||
Row(
|
||||
children: [
|
||||
NumberKey(
|
||||
number: "4",
|
||||
number: list[3],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: "5",
|
||||
number: list[4],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: "6",
|
||||
number: list[5],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
],
|
||||
|
@ -341,21 +517,21 @@ class PinKeyboard extends StatelessWidget {
|
|||
Row(
|
||||
children: [
|
||||
NumberKey(
|
||||
number: "7",
|
||||
number: list[6],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: "8",
|
||||
number: list[7],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: "9",
|
||||
number: list[8],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
],
|
||||
|
@ -365,28 +541,22 @@ class PinKeyboard extends StatelessWidget {
|
|||
),
|
||||
Row(
|
||||
children: [
|
||||
customKey == null
|
||||
? const SizedBox(
|
||||
height: 72,
|
||||
width: 72,
|
||||
)
|
||||
: customKey!,
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: "0",
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
BackspaceKey(
|
||||
onPressed: _backHandler,
|
||||
),
|
||||
// SubmitKey(
|
||||
// onPressed: _submitHandler,
|
||||
// ),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
NumberKey(
|
||||
number: list[9],
|
||||
onPressed: _numberHandler,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
SubmitKey(
|
||||
onPressed: _submitHandler,
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
|
|
104
lib/widgets/dialogs/basic_dialog.dart
Normal file
104
lib/widgets/dialogs/basic_dialog.dart
Normal file
|
@ -0,0 +1,104 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
|
||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||
|
||||
class BasicDialog extends StatelessWidget {
|
||||
const BasicDialog({
|
||||
Key? key,
|
||||
this.leftButton,
|
||||
this.rightButton,
|
||||
this.icon,
|
||||
required this.title,
|
||||
this.message,
|
||||
this.desktopHeight = 474,
|
||||
this.desktopWidth = 641,
|
||||
this.canPopWithBackButton = false,
|
||||
}) : super(key: key);
|
||||
|
||||
final Widget? leftButton;
|
||||
final Widget? rightButton;
|
||||
|
||||
final Widget? icon;
|
||||
|
||||
final String title;
|
||||
final String? message;
|
||||
|
||||
final double? desktopHeight;
|
||||
final double desktopWidth;
|
||||
|
||||
final bool canPopWithBackButton;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDesktop = Util.isDesktop;
|
||||
|
||||
if (isDesktop) {
|
||||
return DesktopDialog(
|
||||
maxHeight: desktopHeight,
|
||||
maxWidth: desktopWidth,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 32),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: STextStyles.desktopH3(context),
|
||||
),
|
||||
const DesktopDialogCloseButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (message != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||
child: Text(
|
||||
message!,
|
||||
style: STextStyles.desktopTextSmall(context),
|
||||
),
|
||||
),
|
||||
if (leftButton != null || rightButton != null)
|
||||
const SizedBox(
|
||||
height: 32,
|
||||
),
|
||||
if (leftButton != null || rightButton != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Row(
|
||||
children: [
|
||||
leftButton != null
|
||||
? Expanded(child: leftButton!)
|
||||
: const Spacer(),
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
rightButton != null
|
||||
? Expanded(child: rightButton!)
|
||||
: const Spacer(),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
return canPopWithBackButton;
|
||||
},
|
||||
child: StackDialog(
|
||||
title: title,
|
||||
leftButton: leftButton,
|
||||
rightButton: rightButton,
|
||||
icon: icon,
|
||||
message: message,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,6 +19,8 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|||
import 'package:stackwallet/utilities/show_loading.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||
import 'package:stackwallet/widgets/dialogs/basic_dialog.dart';
|
||||
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
||||
import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
@ -37,7 +39,7 @@ class SimpleWalletCard extends ConsumerWidget {
|
|||
final bool popPrevious;
|
||||
final NavigatorState? desktopNavigatorState;
|
||||
|
||||
Future<void> _loadTokenWallet(
|
||||
Future<bool> _loadTokenWallet(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
Manager manager,
|
||||
|
@ -52,7 +54,31 @@ class SimpleWalletCard extends ConsumerWidget {
|
|||
),
|
||||
);
|
||||
|
||||
try {
|
||||
await ref.read(tokenServiceProvider)!.initialize();
|
||||
return true;
|
||||
} catch (_) {
|
||||
await showDialog<void>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => BasicDialog(
|
||||
title: "Failed to load token data",
|
||||
desktopHeight: double.infinity,
|
||||
desktopWidth: 450,
|
||||
rightButton: PrimaryButton(
|
||||
label: "OK",
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
if (desktopNavigatorState == null) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void _openWallet(BuildContext context, WidgetRef ref) async {
|
||||
|
@ -91,13 +117,21 @@ class SimpleWalletCard extends ConsumerWidget {
|
|||
final contract =
|
||||
ref.read(mainDBProvider).getEthContractSync(contractAddress!)!;
|
||||
|
||||
await showLoading<void>(
|
||||
whileFuture: _loadTokenWallet(context, ref, manager, contract),
|
||||
context: context,
|
||||
final success = await showLoading<bool>(
|
||||
whileFuture: _loadTokenWallet(
|
||||
desktopNavigatorState?.context ?? context,
|
||||
ref,
|
||||
manager,
|
||||
contract),
|
||||
context: desktopNavigatorState?.context ?? context,
|
||||
opaqueBG: true,
|
||||
message: "Loading ${contract.name}",
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (desktopNavigatorState == null) {
|
||||
// pop loading
|
||||
nav.pop();
|
||||
|
|
|
@ -7,9 +7,13 @@ import 'package:stackwallet/widgets/custom_pin_put/custom_pin_put.dart';
|
|||
import 'package:stackwallet/widgets/custom_pin_put/pin_keyboard.dart';
|
||||
|
||||
void main() {
|
||||
group("CustomPinPut tests", () {
|
||||
testWidgets("CustomPinPut with 4 fields builds correctly", (tester) async {
|
||||
const pinPut = CustomPinPut(fieldsCount: 4);
|
||||
group("CustomPinPut tests, non-random PIN", () {
|
||||
testWidgets("CustomPinPut with 4 fields builds correctly, non-random PIN",
|
||||
(tester) async {
|
||||
const pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
|
@ -31,12 +35,17 @@ void main() {
|
|||
expect(find.byType(NumberKey), findsNWidgets(10));
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut entering a pin successfully", (tester) async {
|
||||
testWidgets("CustomPinPut entering a pin successfully, non-random PIN",
|
||||
(tester) async {
|
||||
bool submittedPinMatches = false;
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
onSubmit: (pin) => submittedPinMatches = pin == "1234",
|
||||
onSubmit: (pin) {
|
||||
submittedPinMatches = pin == "1234";
|
||||
print("pin entered: $pin");
|
||||
},
|
||||
useNativeKeyboard: false,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -69,16 +78,20 @@ void main() {
|
|||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "4"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(SubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(submittedPinMatches, true);
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter fade animation", (tester) async {
|
||||
testWidgets("CustomPinPut pin enter fade animation, non-random PIN",
|
||||
(tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.fade,
|
||||
controller: controller,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -104,12 +117,14 @@ void main() {
|
|||
expect(controller.text, "");
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter scale animation", (tester) async {
|
||||
testWidgets("CustomPinPut pin enter scale animation, non-random PIN",
|
||||
(tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.scale,
|
||||
controller: controller,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -135,12 +150,14 @@ void main() {
|
|||
expect(controller.text, "");
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter rotate animation", (tester) async {
|
||||
testWidgets("CustomPinPut pin enter rotate animation, non-random PIN",
|
||||
(tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.rotation,
|
||||
controller: controller,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -167,11 +184,12 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
testWidgets("PinKeyboard builds correctly", (tester) async {
|
||||
testWidgets("PinKeyboard builds correctly, non-random PIN", (tester) async {
|
||||
final keyboard = PinKeyboard(
|
||||
onNumberKeyPressed: (_) {},
|
||||
onBackPressed: () {},
|
||||
onSubmitPressed: () {},
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -188,6 +206,7 @@ void main() {
|
|||
);
|
||||
|
||||
expect(find.byType(BackspaceKey), findsOneWidget);
|
||||
expect(find.byType(SubmitKey), findsOneWidget);
|
||||
expect(find.byType(NumberKey), findsNWidgets(10));
|
||||
expect(find.text("0"), findsOneWidget);
|
||||
expect(find.text("1"), findsOneWidget);
|
||||
|
@ -199,6 +218,220 @@ void main() {
|
|||
expect(find.text("7"), findsOneWidget);
|
||||
expect(find.text("8"), findsOneWidget);
|
||||
expect(find.text("9"), findsOneWidget);
|
||||
expect(find.byType(SvgPicture), findsOneWidget);
|
||||
expect(find.byType(SvgPicture), findsNWidgets(2));
|
||||
});
|
||||
|
||||
group("CustomPinPut tests, with random PIN", () {
|
||||
testWidgets("CustomPinPut with 4 fields builds correctly, with random PIN",
|
||||
(tester) async {
|
||||
const pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: const Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// expects 5 here. Four + the actual text field text
|
||||
expect(find.text(""), findsNWidgets(5));
|
||||
expect(find.byType(PinKeyboard), findsOneWidget);
|
||||
expect(find.byType(BackspaceKey), findsOneWidget);
|
||||
expect(find.byType(NumberKey), findsNWidgets(10));
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut entering a pin successfully, with random PIN",
|
||||
(tester) async {
|
||||
bool submittedPinMatches = false;
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
onSubmit: (pin) {
|
||||
submittedPinMatches = pin == "1234";
|
||||
print("pin entered: $pin");
|
||||
},
|
||||
useNativeKeyboard: false,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "2"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "6"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "3"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "4"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(SubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(submittedPinMatches, true);
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter fade animation, with random PIN",
|
||||
(tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.fade,
|
||||
controller: controller,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "1");
|
||||
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "");
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter scale animation, with random PIN",
|
||||
(tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.scale,
|
||||
controller: controller,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "1");
|
||||
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "");
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter rotate animation, with random PIN",
|
||||
(tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.rotation,
|
||||
controller: controller,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "1");
|
||||
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "");
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets("PinKeyboard builds correctly, with random PIN", (tester) async {
|
||||
final keyboard = PinKeyboard(
|
||||
onNumberKeyPressed: (_) {},
|
||||
onBackPressed: () {},
|
||||
onSubmitPressed: () {},
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: keyboard,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(BackspaceKey), findsOneWidget);
|
||||
expect(find.byType(SubmitKey), findsOneWidget);
|
||||
expect(find.byType(NumberKey), findsNWidgets(10));
|
||||
expect(find.text("0"), findsOneWidget);
|
||||
expect(find.text("1"), findsOneWidget);
|
||||
expect(find.text("2"), findsOneWidget);
|
||||
expect(find.text("3"), findsOneWidget);
|
||||
expect(find.text("4"), findsOneWidget);
|
||||
expect(find.text("5"), findsOneWidget);
|
||||
expect(find.text("6"), findsOneWidget);
|
||||
expect(find.text("7"), findsOneWidget);
|
||||
expect(find.text("8"), findsOneWidget);
|
||||
expect(find.text("9"), findsOneWidget);
|
||||
expect(find.byType(SvgPicture), findsNWidgets(2));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue