2021-03-02 08:19:20 +01:00
import ' dart:async ' ;
2021-03-02 07:05:47 +01:00
import ' dart:ui ' ;
import ' package:flutter/services.dart ' ;
import ' package:flutter/material.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-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 {
final int progress = 92 ;
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 ( ) ;
return Scaffold (
extendBodyBehindAppBar: true ,
body: SafeArea (
child: Column ( children: < Widget > [
common . onboardingProgressBar ( ' Ma phrase de restauration ' , progress ) ,
common . bubbleSpeak (
" 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). " ) ,
SizedBox ( height: 80 ) ,
2021-03-02 08:19:20 +01:00
pinForm ( context , _walletOptions , 5 , 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 ) ;
return Form (
key: formKey ,
child: Padding (
padding: const EdgeInsets . symmetric ( vertical: 8.0 , horizontal: 30 ) ,
child: PinCodeTextField (
autoFocus: true ,
appContext: context ,
pastedTextStyle: TextStyle (
color: Colors . green . shade600 ,
fontWeight: FontWeight . bold ,
) ,
length: _pinLenght ,
obscureText: false ,
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 {
print ( " Completed " ) ;
final resultWallet = await _walletOptions . readLocalWallet (
_walletNbr , _pin . toUpperCase ( ) , _pinLenght , _derivation ) ;
if ( resultWallet = = ' bad ' ) {
errorController . add ( ErrorAnimationType
. shake ) ; // Triggering error shake animation
hasError = true ;
pinColor = Colors . red [ 600 ] ;
_walletOptions . reloadBuild ( ) ;
} else {
pinColor = Colors . green [ 500 ] ;
_myWalletProvider . getAllWalletsNames ( ) ;
_walletOptions . reloadBuild ( ) ;
Navigator . popUntil (
context ,
ModalRoute . withName ( ' / ' ) ,
) ;
}
} ,
onChanged: ( value ) {
if ( pinColor ! = Color ( 0xFFA4B600 ) ) {
pinColor = Color ( 0xFFA4B600 ) ;
}
print ( value ) ;
} ,
) ) ,
) ;
}
2021-03-02 07:05:47 +01:00
}