2021-03-02 08:19:20 +01:00
import ' dart:async ' ;
2021-03-02 07:05:47 +01:00
import ' dart:ui ' ;
2021-03-06 20:06:41 +01:00
import ' package:dubp/dubp.dart ' ;
2021-03-02 07:05:47 +01:00
import ' package:flutter/services.dart ' ;
import ' package:flutter/material.dart ' ;
2021-03-08 00:32:18 +01:00
import ' package:gecko/globals.dart ' ;
2021-03-06 20:06:41 +01:00
import ' package:gecko/models/generateWallets.dart ' ;
2021-03-02 08:19:20 +01:00
import ' package:gecko/models/myWallets.dart ' ;
import ' package:gecko/models/walletOptions.dart ' ;
2021-03-02 07:05:47 +01:00
import ' package:gecko/screens/commonElements.dart ' ;
2021-03-08 06:21:04 +01:00
import ' package:gecko/screens/onBoarding/13_congratulations.dart ' ;
2021-03-02 08:19:20 +01:00
import ' package:pin_code_fields/pin_code_fields.dart ' ;
2021-03-02 07:05:47 +01:00
import ' package:provider/provider.dart ' ;
// ignore: must_be_immutable
class OnboardingStepFourteen extends StatelessWidget {
2021-03-06 20:06:41 +01:00
OnboardingStepFourteen ( {
Key validationKey ,
@ required this . generatedWallet ,
} ) : super ( key: validationKey ) ;
NewWallet generatedWallet ;
2021-03-08 01:08:26 +01:00
final int progress = 11 ;
2021-03-02 08:19:20 +01:00
final formKey = GlobalKey < FormState > ( ) ;
var pinColor = Color ( 0xFFA4B600 ) ;
bool hasError = false ;
2021-03-02 07:05:47 +01:00
@ override
Widget build ( BuildContext context ) {
SystemChrome . setPreferredOrientations ( [ DeviceOrientation . portraitUp ] ) ;
2021-03-02 08:19:20 +01:00
// GenerateWalletsProvider _generateWalletProvider =
// Provider.of<GenerateWalletsProvider>(context);
WalletOptionsProvider _walletOptions =
Provider . of < WalletOptionsProvider > ( context ) ;
2021-03-02 07:05:47 +01:00
CommonElements common = CommonElements ( ) ;
2021-03-08 00:32:18 +01:00
final int _pinLenght = _walletOptions . getPinLenght ( generatedWallet . dewif ) ;
2021-03-02 07:05:47 +01:00
return Scaffold (
extendBodyBehindAppBar: true ,
body: SafeArea (
child: Column ( children: < Widget > [
2021-03-08 17:23:56 +01:00
common . onboardingProgressBar (
context , ' Ma phrase de restauration ' , progress ) ,
2021-03-02 07:05:47 +01:00
common . bubbleSpeak (
2021-04-24 20:27:18 +02:00
" Avez-vous bien mémorisé votre code secret ? \n \n Vérifions ça ensemble ! \n \n Tapez votre code secret dans le champ ci-dessous (après c’ est fini, promis-juré-gecko). " ,
textKey: Key ( ' step12 ' ) ,
) ,
2021-03-08 00:32:18 +01:00
SizedBox ( height: isTall ? 80 : 10 ) ,
pinForm ( context , _walletOptions , _pinLenght , 1 , 3 )
2021-03-02 07:05:47 +01:00
] ) ,
) ) ;
}
2021-03-02 08:19:20 +01:00
Widget pinForm ( context , WalletOptionsProvider _walletOptions , _pinLenght ,
int _walletNbr , int _derivation ) {
// var _walletPin = '';
// ignore: close_sinks
StreamController < ErrorAnimationType > errorController =
StreamController < ErrorAnimationType > ( ) ;
TextEditingController _enterPin = TextEditingController ( ) ;
MyWalletsProvider _myWalletProvider =
Provider . of < MyWalletsProvider > ( context ) ;
2021-03-06 20:06:41 +01:00
GenerateWalletsProvider _generateWalletProvider =
Provider . of < GenerateWalletsProvider > ( context ) ;
2021-03-02 08:19:20 +01:00
2021-03-19 06:33:48 +01:00
final int _currentChest = _myWalletProvider . getCurrentChest ( ) ;
2021-03-23 16:01:07 +01:00
2021-03-02 08:19:20 +01:00
return Form (
key: formKey ,
child: Padding (
padding: const EdgeInsets . symmetric ( vertical: 8.0 , horizontal: 30 ) ,
child: PinCodeTextField (
2021-04-27 11:51:14 +02:00
key: Key ( ' formKey2 ' ) ,
2021-03-02 08:19:20 +01:00
autoFocus: true ,
appContext: context ,
pastedTextStyle: TextStyle (
color: Colors . green . shade600 ,
fontWeight: FontWeight . bold ,
) ,
length: _pinLenght ,
2021-04-27 11:51:14 +02:00
obscureText: true ,
2021-03-02 08:19:20 +01:00
obscuringCharacter: ' * ' ,
animationType: AnimationType . fade ,
validator: ( v ) {
if ( v . length < _pinLenght ) {
return " Votre code PIN fait $ _pinLenght caractères " ;
} else {
return null ;
}
} ,
pinTheme: PinTheme (
activeColor: pinColor ,
borderWidth: 4 ,
shape: PinCodeFieldShape . box ,
borderRadius: BorderRadius . circular ( 5 ) ,
fieldHeight: 60 ,
fieldWidth: 50 ,
activeFillColor: hasError ? Colors . blueAccent : Colors . black ,
) ,
cursorColor: Colors . black ,
animationDuration: Duration ( milliseconds: 300 ) ,
textStyle: TextStyle ( fontSize: 20 , height: 1.6 ) ,
backgroundColor: Color ( 0xffF9F9F1 ) ,
enableActiveFill: false ,
errorAnimationController: errorController ,
controller: _enterPin ,
keyboardType: TextInputType . text ,
boxShadows: [
BoxShadow (
offset: Offset ( 0 , 1 ) ,
color: Colors . black12 ,
blurRadius: 10 ,
)
] ,
onCompleted: ( _pin ) async {
2021-04-04 18:53:32 +02:00
_myWalletProvider . pinCode = _pin ;
2021-04-05 20:48:28 +02:00
_myWalletProvider . pinLenght = _pinLenght ;
2021-03-06 20:06:41 +01:00
final bool resultWallet = await _walletOptions . checkPinOK (
generatedWallet . dewif , _pin . toUpperCase ( ) , _pinLenght ) ;
if ( resultWallet ) {
2021-03-02 08:19:20 +01:00
pinColor = Colors . green [ 500 ] ;
2021-03-19 06:33:48 +01:00
await _generateWalletProvider . storeHDWChest (
2021-03-11 07:08:45 +01:00
generatedWallet , ' Mon portefeuille courant ' , context ) ;
2021-03-31 02:38:44 +02:00
_myWalletProvider . readAllWallets ( _currentChest ) ;
2021-04-04 15:35:38 +02:00
await _myWalletProvider . getDefaultWalletAsync ( ) ;
2021-04-05 20:48:28 +02:00
scheduleMicrotask ( ( ) {
_walletOptions . reloadBuild ( ) ;
_myWalletProvider . rebuildWidget ( ) ;
} ) ;
2021-03-06 22:26:30 +01:00
Navigator . push (
2021-03-02 08:19:20 +01:00
context ,
2021-03-08 06:21:04 +01:00
FaderTransition (
page: OnboardingStepFiveteen ( ) , isFast: false ) ,
2021-03-02 08:19:20 +01:00
) ;
2021-03-06 20:06:41 +01:00
} else {
errorController . add ( ErrorAnimationType
. shake ) ; // Triggering error shake animation
hasError = true ;
pinColor = Colors . red [ 600 ] ;
_walletOptions . reloadBuild ( ) ;
2021-03-02 08:19:20 +01:00
}
} ,
onChanged: ( value ) {
if ( pinColor ! = Color ( 0xFFA4B600 ) ) {
pinColor = Color ( 0xFFA4B600 ) ;
}
} ,
) ) ,
) ;
}
2021-03-02 07:05:47 +01:00
}