2021-11-21 01:50:05 +01:00
import ' package:bubble/bubble.dart ' ;
2022-06-12 18:03:17 +02:00
import ' package:connectivity_plus/connectivity_plus.dart ' ;
2021-01-26 21:00:26 +01:00
import ' package:gecko/globals.dart ' ;
2022-02-18 02:19:08 +01:00
import ' package:gecko/models/stateful_wrapper.dart ' ;
2021-12-23 15:13:58 +01:00
import ' package:gecko/providers/chest_provider.dart ' ;
2022-05-29 04:30:03 +02:00
import ' package:gecko/providers/home.dart ' ;
2022-02-18 18:57:03 +01:00
import ' package:gecko/providers/substrate_sdk.dart ' ;
2021-12-23 15:13:58 +01:00
import ' package:gecko/providers/wallets_profiles.dart ' ;
2021-01-08 01:20:03 +01:00
import ' package:flutter/material.dart ' ;
2021-12-23 15:13:58 +01:00
import ' package:gecko/providers/my_wallets.dart ' ;
2021-11-14 19:21:20 +01:00
import ' package:gecko/models/wallet_data.dart ' ;
2022-06-01 21:00:17 +02:00
import ' package:gecko/screens/animated_text.dart ' ;
2022-05-29 01:38:27 +02:00
import ' package:gecko/screens/common_elements.dart ' ;
2021-11-21 06:36:12 +01:00
import ' package:gecko/screens/myWallets/restore_chest.dart ' ;
2021-11-14 19:21:20 +01:00
import ' package:gecko/screens/myWallets/unlocking_wallet.dart ' ;
2022-05-31 18:23:56 +02:00
import ' package:gecko/screens/myWallets/wallets_home.dart ' ;
2021-11-21 01:50:05 +01:00
import ' package:gecko/screens/onBoarding/1.dart ' ;
2021-11-23 04:11:45 +01:00
import ' package:gecko/screens/search.dart ' ;
2021-01-28 15:26:26 +01:00
import ' package:gecko/screens/settings.dart ' ;
2021-02-27 20:29:35 +01:00
import ' package:flutter/services.dart ' ;
2022-02-18 00:20:21 +01:00
import ' package:gecko/screens/substrate_sandbox.dart ' ;
2021-01-26 21:00:26 +01:00
import ' package:provider/provider.dart ' ;
2021-01-08 00:12:22 +01:00
2021-01-26 21:00:26 +01:00
class HomeScreen extends StatelessWidget {
2021-12-23 12:36:09 +01:00
const HomeScreen ( { Key ? key } ) : super ( key: key ) ;
2021-11-14 19:21:20 +01:00
2021-01-08 00:12:22 +01:00
@ override
Widget build ( BuildContext context ) {
2021-02-27 20:29:35 +01:00
SystemChrome . setPreferredOrientations ( [ DeviceOrientation . portraitUp ] ) ;
2022-05-30 14:48:12 +02:00
homeContext = context ;
2021-02-27 20:29:35 +01:00
MyWalletsProvider _myWalletProvider =
Provider . of < MyWalletsProvider > ( context ) ;
2021-11-17 06:20:23 +01:00
Provider . of < ChestProvider > ( context ) ;
2022-02-18 18:57:03 +01:00
SubstrateSdk _sub = Provider . of < SubstrateSdk > ( context , listen: false ) ;
2021-03-08 00:32:18 +01:00
2021-11-17 06:20:23 +01:00
final bool isWalletsExists = _myWalletProvider . checkIfWalletExist ( ) ;
2021-11-14 03:12:07 +01:00
2021-03-08 00:32:18 +01:00
isTall = false ;
ratio = 1 ;
if ( MediaQuery . of ( context ) . size . height > = 930 ) {
isTall = true ;
ratio = 1.125 ;
}
2021-01-09 09:17:01 +01:00
return Scaffold (
2021-11-15 18:05:08 +01:00
resizeToAvoidBottomInset: false ,
drawer: Drawer (
child: Column (
children: < Widget > [
Expanded (
child: ListView ( padding: EdgeInsets . zero , children: < Widget > [
DrawerHeader (
child: Column ( children: const < Widget > [
SizedBox ( height: 0 ) ,
Image (
image: AssetImage ( ' assets/icon/gecko_final.png ' ) ,
height: 130 ) ,
] ) ,
decoration: BoxDecoration (
color: orangeC ,
) ,
) ,
ListTile (
key: const Key ( ' parameters ' ) ,
title: const Text ( ' Paramètres ' ) ,
onTap: ( ) {
Navigator . pop ( context ) ;
Navigator . push (
context ,
MaterialPageRoute ( builder: ( context ) {
return SettingsScreen ( ) ;
} ) ,
) ;
} ,
) ,
2022-05-04 16:41:08 +02:00
ListTile (
key: const Key ( ' substrateSandbox ' ) ,
2022-05-21 06:52:30 +02:00
title: const Text ( ' Substrate debug ' ) ,
2022-05-04 16:41:08 +02:00
onTap: ( ) {
Navigator . pop ( context ) ;
Navigator . push (
context ,
MaterialPageRoute ( builder: ( context ) {
return const SubstrateSandBox ( ) ;
} ) ,
) ;
} ,
) ,
2021-12-30 00:51:04 +01:00
// ListTile(
// title: const Text('A propos'),
// onTap: () {
// },
// ),
2021-11-15 18:05:08 +01:00
] ) ) ,
Align (
alignment: FractionalOffset . bottomCenter ,
child: Text ( ' Ğecko v $ appVersion ' ) ) ,
const SizedBox ( height: 20 )
] ,
) ,
) ,
2022-05-27 16:58:03 +02:00
// bottomNavigationBar: _homeProvider.bottomBar(context, 1),
2021-11-15 18:05:08 +01:00
backgroundColor: const Color ( 0xffF9F9F1 ) ,
body: Builder (
builder: ( ctx ) = > StatefulWrapper (
2021-11-21 01:50:05 +01:00
onInit: ( ) {
2022-05-16 22:27:25 +02:00
WidgetsBinding . instance . addPostFrameCallback ( ( _ ) async {
2022-02-18 18:57:03 +01:00
if ( ! _sub . sdkReady & & ! _sub . sdkLoading ) await _sub . initApi ( ) ;
2022-05-04 16:41:08 +02:00
if ( _sub . sdkReady & & ! _sub . nodeConnected ) {
2022-05-29 04:30:03 +02:00
// Check if versionData non compatible, drop everything
2022-05-29 01:38:27 +02:00
if ( walletBox . isNotEmpty & &
walletBox . getAt ( 0 ) ! . version ! < dataVersion ) {
await infoPopup ( context ,
" La version de vos coffres n'est plus comptabile avec cette version de Ğecko. \n Tous vos coffres vont être oubliés, vous devez les importer de nouveau. " ) ;
await walletBox . clear ( ) ;
await chestBox . clear ( ) ;
await configBox . delete ( ' defaultWallet ' ) ;
await _sub . deleteAllAccounts ( ) ;
_myWalletProvider . rebuildWidget ( ) ;
}
2022-06-12 18:03:17 +02:00
var connectivityResult =
await ( Connectivity ( ) . checkConnectivity ( ) ) ;
2022-06-12 19:43:13 +02:00
HomeProvider _homeProvider =
Provider . of < HomeProvider > ( ctx , listen: false ) ;
2022-06-12 18:03:17 +02:00
if ( connectivityResult ! = ConnectivityResult . mobile & &
connectivityResult ! = ConnectivityResult . wifi ) {
_homeProvider . changeMessage (
" Vous n'êtes pas connecté à internet " , 0 ) ;
_sub . nodeConnected = false ;
}
Connectivity ( )
. onConnectivityChanged
. listen ( ( ConnectivityResult result ) async {
log . d ( ' Network changed: $ result ' ) ;
2022-06-12 19:43:13 +02:00
if ( result = = ConnectivityResult . none ) {
_sub . nodeConnected = false ;
await _sub . sdk . api . setting . unsubscribeBestNumber ( ) ;
_homeProvider . changeMessage (
" Vous n'êtes pas connecté à internet " , 0 ) ;
_sub . reload ( ) ;
} else {
await _sub . connectNode ( ctx ) ;
}
2022-06-12 18:03:17 +02:00
} ) ;
2022-05-04 16:41:08 +02:00
}
2021-11-21 01:50:05 +01:00
} ) ;
} ,
child: isWalletsExists ? geckHome ( context ) : welcomeHome ( context )
// bottomNavigationBar: BottomNavigationBar(
// backgroundColor: backgroundColor,
// fixedColor: Colors.grey[850],
// unselectedItemColor: const Color(0xffBD935C),
// type: BottomNavigationBarType.fixed,
// onTap: (index) {
// _homeProvider.currentIndex = index;
// },
// currentIndex: _homeProvider.currentIndex,
// items: [
// BottomNavigationBarItem(
// icon: Image.asset('assets/block-space-disabled.png', height: 26),
// activeIcon: Image.asset('assets/blockchain.png', height: 26),
// label: 'Explorateur',
// ),
// const BottomNavigationBarItem(
// icon: Icon(Icons.lock),
// label: 'Mes portefeuilles',
// ),
// ],
// ),
) ,
) ,
) ;
}
}
Widget geckHome ( context ) {
MyWalletsProvider _myWalletProvider = Provider . of < MyWalletsProvider > ( context ) ;
Provider . of < ChestProvider > ( context ) ;
2021-11-30 01:25:48 +01:00
WalletsProfilesProvider _historyProvider =
Provider . of < WalletsProfilesProvider > ( context ) ;
2021-11-21 01:50:05 +01:00
final double statusBarHeight = MediaQuery . of ( context ) . padding . top ;
return Container (
decoration: const BoxDecoration (
image: DecorationImage (
image: AssetImage ( " assets/home/background.jpg " ) ,
fit: BoxFit . cover ,
) ,
) ,
child:
Column ( crossAxisAlignment: CrossAxisAlignment . start , children: < Widget > [
Stack ( children: < Widget > [
Positioned (
top: statusBarHeight + 10 ,
left: 15 ,
child: Builder (
builder: ( context ) = > IconButton (
key: const Key ( ' drawerMenu ' ) ,
icon: const Icon (
Icons . menu ,
color: Colors . white ,
size: 35 ,
2021-11-19 00:17:00 +01:00
) ,
2021-11-21 01:50:05 +01:00
onPressed: ( ) = > Scaffold . of ( context ) . openDrawer ( ) ,
2021-11-15 18:05:08 +01:00
) ,
2021-11-21 01:50:05 +01:00
) ,
) ,
const Align (
child:
Image ( image: AssetImage ( ' assets/home/header.png ' ) , height: 210 ) ,
) ,
] ) ,
Padding (
padding: EdgeInsets . only ( top: 15 * ratio ) ,
2022-05-29 04:30:03 +02:00
child:
Row ( mainAxisAlignment: MainAxisAlignment . center , children: < Widget > [
2022-06-01 21:00:17 +02:00
DefaultTextStyle (
textAlign: TextAlign . center ,
style: const TextStyle (
color: Colors . white ,
fontSize: 24 ,
fontWeight: FontWeight . w700 ,
shadows: < Shadow > [
Shadow (
offset: Offset ( 0 , 0 ) ,
blurRadius: 20 ,
color: Colors . black ,
) ,
Shadow (
offset: Offset ( 0 , 0 ) ,
blurRadius: 20 ,
color: Colors . black ,
) ,
] ,
) ,
child: Consumer < HomeProvider > ( builder: ( context , _homeP , _ ) {
return AnimatedFadeOutIn < String > (
data: _homeP . homeMessage ,
duration: const Duration ( milliseconds: 100 ) ,
builder: ( value ) = > Text ( value ) ,
) ;
} ) ,
) ,
2022-05-29 04:30:03 +02:00
] ) ,
2021-11-21 01:50:05 +01:00
) ,
2022-02-18 00:20:21 +01:00
const SizedBox ( height: 15 ) ,
2021-11-21 01:50:05 +01:00
Expanded (
flex: 1 ,
child: Container (
decoration: BoxDecoration (
gradient: LinearGradient (
begin: Alignment . topCenter ,
end: Alignment . bottomCenter ,
colors: [
Colors . transparent ,
Colors . black . withOpacity ( 0.9 ) ,
] ,
) ,
) ,
child: Column ( children: < Widget > [
const Spacer ( ) ,
Row ( mainAxisAlignment: MainAxisAlignment . center , children: < Widget > [
Column ( children: < Widget > [
Container (
child: ClipOval (
child: Material (
color: orangeC , // button color
child: InkWell (
2022-05-25 20:40:25 +02:00
child: Padding (
padding: const EdgeInsets . all ( 18 ) ,
2021-11-23 04:11:45 +01:00
child: Image (
2022-05-25 20:40:25 +02:00
image:
const AssetImage ( ' assets/home/loupe.png ' ) ,
height: 62 * ratio ) ,
2021-11-23 04:11:45 +01:00
) ,
2021-11-21 01:50:05 +01:00
onTap: ( ) {
2021-11-23 04:11:45 +01:00
Navigator . push (
context ,
MaterialPageRoute ( builder: ( context ) {
return const SearchScreen ( ) ;
} ) ,
) ;
2021-11-21 01:50:05 +01:00
} ) ,
) ,
) ,
decoration: const BoxDecoration (
shape: BoxShape . circle ,
color: Colors . black ,
boxShadow: [
BoxShadow (
blurRadius: 2 ,
offset: Offset ( 1 , 1.5 ) ,
spreadRadius: 0.5 )
] ,
) ,
2021-11-19 03:18:39 +01:00
) ,
2021-11-21 01:50:05 +01:00
const SizedBox ( height: 12 ) ,
2022-05-25 20:40:25 +02:00
Text (
2021-12-02 07:23:12 +01:00
" Rechercher un \n portefeuille " ,
2021-11-21 01:50:05 +01:00
textAlign: TextAlign . center ,
style: TextStyle (
color: Colors . white ,
2022-05-25 20:40:25 +02:00
fontSize: 15 * ratio ,
2021-11-21 01:50:05 +01:00
fontWeight: FontWeight . w500 ) ,
)
2021-11-19 03:18:39 +01:00
] ) ,
2021-11-21 01:50:05 +01:00
const SizedBox ( width: 120 ) ,
Column ( children: < Widget > [
Container (
child: ClipOval (
key: const Key ( ' manageWallets ' ) ,
child: Material (
color: orangeC , // button color
child: InkWell (
2022-05-25 20:40:25 +02:00
child: Padding (
padding: const EdgeInsets . all ( 18 ) ,
2021-11-21 01:50:05 +01:00
child: Image (
2022-05-25 20:40:25 +02:00
image: const AssetImage (
' assets/home/wallet.png ' ) ,
height: 68 * ratio ) ) ,
2022-05-31 18:23:56 +02:00
onTap: ( ) async {
2021-12-23 12:36:09 +01:00
WalletData ? defaultWallet =
2022-05-26 02:19:29 +02:00
_myWalletProvider . getDefaultWallet ( ) ;
2022-05-31 18:23:56 +02:00
String ? _pin ;
if ( _myWalletProvider . pinCode = = ' ' ) {
_pin = await Navigator . push (
context ,
MaterialPageRoute (
builder: ( homeContext ) {
return UnlockingWallet (
wallet: defaultWallet ) ;
} ,
) ,
) ;
}
if ( _pin ! = null | |
_myWalletProvider . pinCode ! = ' ' ) {
Navigator . push (
context ,
MaterialPageRoute ( builder: ( context ) {
return const WalletsHome ( ) ;
} ) ,
) ;
}
// log.d(_myWalletProvider.pinCode);
2021-11-21 01:50:05 +01:00
// Navigator.pushNamed(
// context, '/mywallets')));
} ) ,
) ,
) ,
decoration: const BoxDecoration (
shape: BoxShape . circle ,
color: Colors . black ,
boxShadow: [
BoxShadow (
blurRadius: 2 ,
offset: Offset ( 1 , 1.5 ) ,
spreadRadius: 0.5 )
] ,
) ,
) ,
const SizedBox ( height: 12 ) ,
2022-05-25 20:40:25 +02:00
Text (
2021-11-21 01:50:05 +01:00
" Gérer mes \n portefeuilles " ,
textAlign: TextAlign . center ,
style: TextStyle (
color: Colors . white ,
2022-05-25 20:40:25 +02:00
fontSize: 15 * ratio ,
2021-11-21 01:50:05 +01:00
fontWeight: FontWeight . w500 ) ,
)
] )
] ) ,
Padding (
2022-05-25 20:40:25 +02:00
padding: EdgeInsets . only ( top: 35 * ratio ) ,
2021-11-21 01:50:05 +01:00
child: Row (
mainAxisAlignment: MainAxisAlignment . center ,
children: < Widget > [
Column ( children: < Widget > [
Container (
child: ClipOval (
child: Material (
color: orangeC , // button color
child: InkWell (
2022-05-25 20:40:25 +02:00
child: Padding (
padding: const EdgeInsets . all ( 18 ) ,
2021-11-21 01:50:05 +01:00
child: Image (
2022-05-25 20:40:25 +02:00
image: const AssetImage (
2021-11-21 01:50:05 +01:00
' assets/home/qrcode.png ' ) ,
2022-05-25 20:40:25 +02:00
height: 68 * ratio ) ) ,
2021-11-21 01:50:05 +01:00
onTap: ( ) async {
await _historyProvider . scan ( context ) ;
} ) ,
) ,
) ,
decoration: const BoxDecoration (
shape: BoxShape . circle ,
color: Colors . black ,
boxShadow: [
BoxShadow (
blurRadius: 2 ,
offset: Offset ( 1 , 1.5 ) ,
spreadRadius: 0.5 )
2021-11-19 03:18:39 +01:00
] ,
) ,
2021-11-21 01:50:05 +01:00
) ,
const SizedBox ( height: 12 ) ,
2022-05-25 20:40:25 +02:00
Text (
2021-11-21 01:50:05 +01:00
" Scanner un \n QR code " ,
textAlign: TextAlign . center ,
style: TextStyle (
color: Colors . white ,
2022-05-25 20:40:25 +02:00
fontSize: 15 * ratio ,
2021-11-21 01:50:05 +01:00
fontWeight: FontWeight . w500 ) ,
2021-11-19 03:18:39 +01:00
)
2021-11-21 01:50:05 +01:00
] )
] ) ,
) ,
SizedBox ( height: isTall ? 80 : 40 )
] ) ,
) ,
)
] ) ,
) ;
}
Widget welcomeHome ( context ) {
final double statusBarHeight = MediaQuery . of ( context ) . padding . top ;
return Container (
decoration: const BoxDecoration (
image: DecorationImage (
image: AssetImage ( " assets/home/background.jpg " ) ,
fit: BoxFit . cover ,
) ,
) ,
child:
Column ( crossAxisAlignment: CrossAxisAlignment . start , children: < Widget > [
Stack ( children: < Widget > [
Positioned (
top: statusBarHeight + 10 ,
left: 15 ,
child: Builder (
builder: ( context ) = > IconButton (
key: const Key ( ' drawerMenu ' ) ,
icon: const Icon (
Icons . menu ,
color: Colors . white ,
size: 35 ,
2021-11-19 03:18:39 +01:00
) ,
2021-11-21 01:50:05 +01:00
onPressed: ( ) = > Scaffold . of ( context ) . openDrawer ( ) ,
) ,
) ,
) ,
const Align (
child:
Image ( image: AssetImage ( ' assets/home/header.png ' ) , height: 210 ) ,
) ,
] ) ,
Padding (
padding: EdgeInsets . only ( top: 1 * ratio ) ,
2022-05-20 15:15:29 +02:00
child:
Row ( mainAxisAlignment: MainAxisAlignment . center , children: < Widget > [
Text (
" L’ application de paiement $ currencyName \n plus rapide qu’ un reptile du Vietnam " ,
textAlign: TextAlign . center ,
style: const TextStyle (
color: Colors . white ,
fontSize: 24 ,
fontWeight: FontWeight . w700 ,
shadows: < Shadow > [
Shadow (
offset: Offset ( 0 , 0 ) ,
blurRadius: 20 ,
color: Colors . black ,
2021-11-19 03:18:39 +01:00
) ,
2022-05-20 15:15:29 +02:00
Shadow (
offset: Offset ( 0 , 0 ) ,
blurRadius: 20 ,
color: Colors . black ,
) ,
] ,
) ,
)
] ) ,
2021-11-15 18:05:08 +01:00
) ,
2021-11-21 01:50:05 +01:00
Expanded (
2021-12-24 15:27:38 +01:00
flex: 1 ,
child: Container (
decoration: BoxDecoration (
gradient: LinearGradient (
begin: Alignment . topCenter ,
end: Alignment . bottomCenter ,
colors: [
Colors . transparent ,
Colors . black . withOpacity ( 0.9 ) ,
] ,
2021-11-21 01:50:05 +01:00
) ,
2021-12-24 15:27:38 +01:00
) ,
child: Center (
child: ConstrainedBox (
constraints: const BoxConstraints ( maxWidth: 480 ) ,
2021-11-21 01:50:05 +01:00
child: Column ( children: < Widget > [
const Spacer ( ) ,
Row ( children: < Widget > [
Expanded (
child: Stack ( children: < Widget > [
const Padding (
padding: EdgeInsets . only ( top: 55 ) ,
child: Image (
image: AssetImage ( ' assets/home/gecko-bienvenue.png ' ) ,
height: 220 ,
) ,
) ,
Positioned (
left: 180 ,
child: bubbleSpeak ( " y'a pas de lézard ! " ) ,
) ,
const Positioned (
left: 200 ,
top: 60 ,
child: Image (
image: AssetImage ( ' assets/home/bout_de_bulle.png ' ) ,
) ,
) ,
] ) ,
) ,
] ) ,
SizedBox (
width: 410 ,
height: 70 ,
child: ElevatedButton (
style: ElevatedButton . styleFrom (
elevation: 4 ,
primary: orangeC , // background
onPrimary: Colors . white , // foreground
) ,
onPressed: ( ) {
Navigator . push (
context ,
MaterialPageRoute (
builder: ( context ) {
2022-05-23 10:53:44 +02:00
return const OnboardingStepOne ( ) ;
2021-11-21 01:50:05 +01:00
} ,
) ,
) ;
} ,
child: const Text (
2021-12-02 07:23:12 +01:00
' Créer un portefeuille ' ,
2021-11-21 01:50:05 +01:00
style:
TextStyle ( fontSize: 24 , fontWeight: FontWeight . w600 ) ,
) ,
) ,
) ,
SizedBox ( height: 25 * ratio ) ,
SizedBox (
width: 410 ,
height: 70 ,
child: OutlinedButton (
style: OutlinedButton . styleFrom (
side: BorderSide ( width: 4 , color: orangeC ) ) ,
onPressed: ( ) {
2021-11-21 06:36:12 +01:00
Navigator . push (
context ,
MaterialPageRoute (
builder: ( context ) {
return const RestoreChest ( ) ;
} ,
) ,
) ;
2021-11-21 01:50:05 +01:00
} ,
child: Text (
" Restaurer mes portefeuilles " ,
style: TextStyle (
fontSize: 24 ,
color: orangeC ,
fontWeight: FontWeight . w600 ) ,
) ,
) ,
) ,
SizedBox ( height: isTall ? 100 : 50 )
] ) ,
) ,
2021-12-24 15:27:38 +01:00
) ,
) ,
)
2021-11-21 01:50:05 +01:00
] ) ,
) ;
2021-02-22 19:44:58 +01:00
}
2021-12-23 12:36:09 +01:00
Widget bubbleSpeak ( String text , { double ? long , Key ? textKey } ) {
2021-11-21 01:50:05 +01:00
return Bubble (
padding: long = = null
? const BubbleEdges . all ( 20 )
: BubbleEdges . symmetric ( horizontal: long , vertical: 30 ) ,
elevation: 5 ,
2022-05-29 00:00:57 +02:00
color: backgroundColor ,
2021-11-21 01:50:05 +01:00
child: Text (
text ,
key: textKey ,
style: const TextStyle (
color: Colors . black , fontSize: 21 , fontWeight: FontWeight . w400 ) ,
) ,
) ;
}