2021-11-14 19:21:20 +01:00
// ignore_for_file: file_names
2021-02-28 02:38:52 +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 ' ;
2022-05-23 10:53:44 +02:00
import ' package:gecko/providers/generate_wallets.dart ' ;
import ' package:gecko/providers/my_wallets.dart ' ;
2021-11-14 19:21:20 +01:00
import ' package:gecko/screens/common_elements.dart ' ;
2021-03-08 06:21:04 +01:00
import ' package:gecko/screens/onBoarding/6.dart ' ;
2022-05-23 10:53:44 +02:00
import ' package:printing/printing.dart ' ;
import ' package:provider/provider.dart ' ;
2021-02-28 02:38:52 +01:00
2022-05-23 10:53:44 +02:00
AsyncSnapshot < List > ? mnemoList ;
2021-02-28 02:38:52 +01:00
2022-05-29 01:38:27 +02:00
class OnboardingStepFive extends StatefulWidget {
2022-05-25 20:40:25 +02:00
const OnboardingStepFive ( { Key ? key , this . skipIntro = false } )
: super ( key: key ) ;
final bool skipIntro ;
2021-11-14 19:21:20 +01:00
2022-05-29 01:38:27 +02:00
@ override
State < StatefulWidget > createState ( ) {
return _ChooseChestState ( ) ;
}
}
// ignore: unused_element
class _ChooseChestState extends State < OnboardingStepFive > {
2021-02-28 02:38:52 +01:00
@ override
Widget build ( BuildContext context ) {
SystemChrome . setPreferredOrientations ( [ DeviceOrientation . portraitUp ] ) ;
2022-05-23 10:53:44 +02:00
GenerateWalletsProvider _generateWalletProvider =
Provider . of < GenerateWalletsProvider > ( context , listen: false ) ;
2022-05-29 01:38:27 +02:00
final CommonElements common = CommonElements ( ) ;
2021-03-01 04:48:28 +01:00
2021-02-28 02:38:52 +01:00
return Scaffold (
2022-05-29 00:00:57 +02:00
backgroundColor: backgroundColor ,
2022-05-23 10:53:44 +02:00
appBar: AppBar (
toolbarHeight: 60 * ratio ,
title: const SizedBox (
height: 22 ,
child: Text (
' Votre phrase de restauration ' ,
style: TextStyle ( fontWeight: FontWeight . w600 ) ,
) ,
) ,
) ,
extendBodyBehindAppBar: true ,
body: SafeArea (
child: Column ( children: [
SizedBox ( height: isTall ? 40 : 20 ) ,
common . buildProgressBar ( 4 ) ,
SizedBox ( height: isTall ? 40 : 20 ) ,
common . buildText (
< TextSpan > [
const TextSpan (
text:
' Gecko a généré votre phrase de restauration ! Tâchez de la garder bien secrète, car elle permet à quiconque la connaît d’ accéder à tous vos portefeuilles. ' ) ,
] ,
) ,
2022-05-25 20:40:25 +02:00
SizedBox ( height: 35 * ratio ) ,
2022-05-23 10:53:44 +02:00
sentanceArray ( context ) ,
2022-05-25 20:40:25 +02:00
SizedBox ( height: 17 * ratio ) ,
2022-05-23 10:53:44 +02:00
GestureDetector (
onTap: ( ) {
Navigator . push (
context ,
MaterialPageRoute ( builder: ( context ) {
return PrintWallet ( _generateWalletProvider . generatedMnemonic ) ;
} ) ,
) ;
} ,
child: Image . asset (
' assets/printer.png ' ,
2022-05-25 20:40:25 +02:00
height: 42 * ratio ,
2021-02-28 02:38:52 +01:00
) ,
2022-05-23 10:53:44 +02:00
) ,
const SizedBox ( height: 40 ) ,
Expanded (
child: Align (
2021-02-28 02:38:52 +01:00
alignment: Alignment . bottomCenter ,
2022-05-23 10:53:44 +02:00
child: SizedBox (
2022-05-25 20:40:25 +02:00
width: 380 * ratio ,
height: 60 * ratio ,
2022-05-23 10:53:44 +02:00
child: ElevatedButton (
key: const Key ( ' generateMnemonic ' ) ,
style: ElevatedButton . styleFrom (
elevation: 4 ,
primary: const Color ( 0xffFFD58D ) ,
onPrimary: Colors . black , // foreground
) ,
onPressed: ( ) {
2022-05-29 01:38:27 +02:00
// _generateWalletProvider.reloadBuild();
setState ( ( ) { } ) ;
2022-05-23 10:53:44 +02:00
} ,
2022-05-25 20:40:25 +02:00
child: Text ( " Choisir une autre phrase " ,
2022-05-23 10:53:44 +02:00
style: TextStyle (
2022-05-25 20:40:25 +02:00
fontSize: 22 * ratio ,
fontWeight: FontWeight . w600 ) ) ) ,
2022-05-23 10:53:44 +02:00
) ,
2021-02-28 02:38:52 +01:00
) ,
2022-05-23 10:53:44 +02:00
) ,
2022-05-25 20:40:25 +02:00
SizedBox ( height: 22 * ratio ) ,
2022-05-29 01:38:27 +02:00
nextButton ( context , " J'ai noté ma phrase " , false , widget . skipIntro ) ,
2022-05-25 20:40:25 +02:00
SizedBox ( height: 35 * ratio ) ,
2022-05-23 10:53:44 +02:00
] ) ,
) ,
) ;
2021-02-28 02:38:52 +01:00
}
}
2022-05-23 10:53:44 +02:00
Widget sentanceArray ( BuildContext context ) {
GenerateWalletsProvider _generateWalletProvider =
2022-05-29 01:38:27 +02:00
Provider . of < GenerateWalletsProvider > ( context , listen: false ) ;
2022-05-23 10:53:44 +02:00
return Padding (
padding: const EdgeInsets . symmetric ( horizontal: 3 ) ,
child: Container (
constraints: const BoxConstraints ( maxWidth: 450 ) ,
decoration: BoxDecoration (
border: Border . all ( color: Colors . black ) ,
color: const Color ( 0xffeeeedd ) ,
borderRadius: const BorderRadius . all (
Radius . circular ( 10 ) ,
) ) ,
padding: const EdgeInsets . all ( 20 ) ,
child: FutureBuilder (
future: _generateWalletProvider . generateWordList ( context ) ,
builder: ( BuildContext context , AsyncSnapshot < List > _data ) {
if ( ! _data . hasData ) {
return const Text ( ' ' ) ;
} else {
mnemoList = _data ;
return Column (
mainAxisAlignment: MainAxisAlignment . center ,
mainAxisSize: MainAxisSize . max ,
crossAxisAlignment: CrossAxisAlignment . center ,
children: < Widget > [
Row ( children: < Widget > [
arrayCell ( _data . data ! [ 0 ] ) ,
arrayCell ( _data . data ! [ 1 ] ) ,
arrayCell ( _data . data ! [ 2 ] ) ,
arrayCell ( _data . data ! [ 3 ] ) ,
] ) ,
const SizedBox ( height: 15 ) ,
Row ( children: < Widget > [
arrayCell ( _data . data ! [ 4 ] ) ,
arrayCell ( _data . data ! [ 5 ] ) ,
arrayCell ( _data . data ! [ 6 ] ) ,
arrayCell ( _data . data ! [ 7 ] ) ,
] ) ,
const SizedBox ( height: 15 ) ,
Row ( children: < Widget > [
arrayCell ( _data . data ! [ 8 ] ) ,
arrayCell ( _data . data ! [ 9 ] ) ,
arrayCell ( _data . data ! [ 10 ] ) ,
arrayCell ( _data . data ! [ 11 ] ) ,
] ) ,
] ) ;
}
} ) ,
) ,
) ;
}
Widget arrayCell ( dataWord ) {
return SizedBox (
width: 100 ,
child: Column ( children: < Widget > [
Text (
dataWord . split ( ' : ' ) [ 0 ] ,
2022-05-25 20:40:25 +02:00
style: TextStyle ( fontSize: 13 * ratio , color: const Color ( 0xff6b6b52 ) ) ,
2022-05-23 10:53:44 +02:00
) ,
Text (
dataWord . split ( ' : ' ) [ 1 ] ,
key: Key ( ' word ${ dataWord . split ( ' : ' ) [ 0 ] } ' ) ,
2022-05-25 20:40:25 +02:00
style: TextStyle ( fontSize: 17 * ratio , color: Colors . black ) ,
2022-05-23 10:53:44 +02:00
) ,
] ) ,
) ;
}
// ignore: must_be_immutable
class PrintWallet extends StatelessWidget {
const PrintWallet ( this . sentence , { Key ? key } ) : super ( key: key ) ;
final String ? sentence ;
@ override
Widget build ( BuildContext context ) {
GenerateWalletsProvider _generateWalletProvider =
2022-05-29 01:38:27 +02:00
Provider . of < GenerateWalletsProvider > ( context , listen: false ) ;
2022-05-23 10:53:44 +02:00
return MaterialApp (
home: Scaffold (
appBar: AppBar (
leading: IconButton (
icon: const Icon ( Icons . arrow_back , color: Colors . black ) ,
onPressed: ( ) {
Navigator . pop ( context ) ;
} ) ,
backgroundColor: yellowC ,
foregroundColor: Colors . black ,
toolbarHeight: 60 * ratio ,
title: const SizedBox (
height: 22 ,
child: Text (
' Imprimer ma phrase de restauration ' ,
style: TextStyle ( fontWeight: FontWeight . w600 ) ,
) ,
) ,
) ,
body: PdfPreview (
canDebug: false ,
canChangeOrientation: false ,
build: ( format ) = > _generateWalletProvider . printWallet ( mnemoList ) ,
) ,
) ,
) ;
}
}
2022-05-25 20:40:25 +02:00
Widget nextButton (
BuildContext context , String text , bool isFast , bool skipIntro ) {
2022-05-23 10:53:44 +02:00
GenerateWalletsProvider _generateWalletProvider =
Provider . of < GenerateWalletsProvider > ( context , listen: false ) ;
MyWalletsProvider _myWalletProvider =
Provider . of < MyWalletsProvider > ( context , listen: false ) ;
return SizedBox (
2022-05-25 20:40:25 +02:00
width: 380 * ratio ,
height: 60 * ratio ,
2022-05-23 10:53:44 +02:00
child: ElevatedButton (
style: ElevatedButton . styleFrom (
elevation: 4 ,
primary: orangeC , // background
onPrimary: Colors . white , // foreground
) ,
onPressed: ( ) {
_generateWalletProvider . nbrWord =
_generateWalletProvider . getRandomInt ( ) ;
_generateWalletProvider . nbrWordAlpha = _generateWalletProvider
. intToString ( _generateWalletProvider . nbrWord + 1 ) ;
_myWalletProvider . mnemonic = _generateWalletProvider . generatedMnemonic ! ;
Navigator . push (
context ,
FaderTransition (
page: OnboardingStepSix (
2022-05-25 20:40:25 +02:00
generatedMnemonic: _generateWalletProvider . generatedMnemonic ,
skipIntro: skipIntro ) ,
2022-05-23 10:53:44 +02:00
isFast: true ) ,
) ;
} ,
child: Text (
text ,
2022-05-25 20:40:25 +02:00
style: TextStyle ( fontSize: 22 * ratio , fontWeight: FontWeight . w600 ) ,
2022-05-23 10:53:44 +02:00
) ,
) ,
) ;
}