gecko/lib/screens/myWallets/choose_wallet.dart

236 lines
9.0 KiB
Dart
Raw Normal View History

2022-09-05 04:15:27 +02:00
// ignore_for_file: use_build_context_synchronously, must_be_immutable
2022-05-28 21:15:47 +02:00
import 'dart:io';
2022-06-17 01:13:14 +02:00
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:flutter/material.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:gecko/providers/my_wallets.dart';
2022-05-19 13:44:22 +02:00
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallet_options.dart';
import 'package:gecko/screens/myWallets/wallets_home.dart';
import 'package:provider/provider.dart';
// import 'package:gecko/models/home.dart';
// import 'package:provider/provider.dart';
class ChooseWalletScreen extends StatelessWidget {
ChooseWalletScreen({Key? key, required this.pin}) : super(key: key);
2022-05-19 13:44:22 +02:00
final String pin;
2022-05-28 21:15:47 +02:00
WalletData? selectedWallet;
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
final int chest = configBox.get('currentChest');
2022-05-25 20:40:55 +02:00
return Scaffold(
2022-05-29 00:00:57 +02:00
backgroundColor: backgroundColor,
appBar: AppBar(
toolbarHeight: 60 * ratio,
2022-06-18 03:01:22 +02:00
title: SizedBox(
height: 22,
2022-06-18 03:01:22 +02:00
child: Text('choiceOfSourceWallet'.tr()),
)),
body: SafeArea(
child: Stack(children: [
2022-05-19 13:44:22 +02:00
myWalletsTiles(context, chest),
Positioned.fill(
bottom: 60,
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: 470,
height: 70,
child: ElevatedButton(
2022-08-24 21:53:16 +02:00
key: keyConfirm,
style: ElevatedButton.styleFrom(
2022-09-05 08:12:24 +02:00
foregroundColor: Colors.white, elevation: 4,
backgroundColor: orangeC, // foreground
),
onPressed: () async {
await sub.setCurrentWallet(selectedWallet!);
sub.reload();
2022-05-28 21:15:47 +02:00
// Navigator.pop(context);
2022-05-25 20:40:55 +02:00
Navigator.pop(context);
2022-05-26 02:19:29 +02:00
Navigator.pop(context);
},
2022-06-17 01:13:14 +02:00
child: Text(
'chooseThisWallet'.tr(),
2022-06-17 20:18:54 +02:00
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.w600),
),
),
),
),
),
]),
));
}
Widget myWalletsTiles(BuildContext context, int currentChest) {
MyWalletsProvider myWalletProvider =
Provider.of<MyWalletsProvider>(context);
2022-05-28 21:15:47 +02:00
// SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
WalletData? defaultWallet = myWalletProvider.getDefaultWallet();
2022-06-02 15:43:22 +02:00
selectedWallet ??= defaultWallet;
myWalletProvider.readAllWallets(currentChest);
if (!isWalletsExists) {
return const Text('');
}
if (myWalletProvider.listWallets.isEmpty) {
return Column(children: const <Widget>[
Center(
child: Text(
'Veuillez générer votre premier portefeuille',
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
)),
]);
}
List listWallets = myWalletProvider.listWallets;
final double screenWidth = MediaQuery.of(context).size.width;
int nTule = 2;
if (screenWidth >= 900) {
nTule = 4;
} else if (screenWidth >= 650) {
nTule = 3;
}
return CustomScrollView(slivers: <Widget>[
const SliverToBoxAdapter(child: SizedBox(height: 20)),
SliverGrid.count(
key: keyListWallets,
crossAxisCount: nTule,
childAspectRatio: 1,
crossAxisSpacing: 0,
mainAxisSpacing: 0,
children: <Widget>[
for (WalletData repository in listWallets as Iterable<WalletData>)
Padding(
padding: const EdgeInsets.all(16),
child: GestureDetector(
2022-08-24 21:53:16 +02:00
key: keySelectThisWallet(repository.address!),
onTap: () {
selectedWallet = repository;
2022-09-09 01:12:17 +02:00
myWalletProvider.reload();
},
child: ClipOvalShadow(
shadow: const Shadow(
color: Colors.transparent,
offset: Offset(0, 0),
blurRadius: 5,
),
clipper: CustomClipperOval(),
child: ClipRRect(
borderRadius:
const BorderRadius.all(Radius.circular(12)),
child: Column(children: <Widget>[
Expanded(
child: Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
gradient: RadialGradient(
radius: 0.6,
colors: [
Colors.green[400]!,
const Color(0xFFE7E7A6),
],
)),
child: repository.imageCustomPath == null
? Image.asset(
'assets/avatars/${repository.imageDefaultPath}',
alignment: Alignment.bottomCenter,
scale: 0.5,
)
2022-05-28 21:15:47 +02:00
: Container(
width: 120,
height: 120,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.transparent,
image: DecorationImage(
fit: BoxFit.contain,
image: FileImage(
File(repository.imageCustomPath!),
2022-05-28 21:15:47 +02:00
),
),
),
),
)),
balanceBuilder(context, repository.address!,
selectedWallet!.address == repository.address!),
ListTile(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(12),
),
),
2022-05-28 21:15:47 +02:00
tileColor:
repository.address == selectedWallet!.address
2022-05-28 21:15:47 +02:00
? orangeC
: const Color(0xffFFD58D),
title: Center(
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 5),
child: Text(
repository.name!,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 17.0,
color: repository.address ==
2022-05-28 21:15:47 +02:00
selectedWallet!.address
? const Color(0xffF9F9F1)
: Colors.black,
fontStyle: FontStyle.italic),
),
),
),
onTap: () async {
selectedWallet = repository;
2022-09-09 01:12:17 +02:00
myWalletProvider.reload();
},
)
]),
),
),
)),
]),
]);
}
Widget balanceBuilder(context, String address, bool isDefault) {
return Container(
width: double.infinity,
color: isDefault ? orangeC : yellowC,
child: SizedBox(
2022-09-11 13:14:52 +02:00
height: 30,
child: Column(children: [
const Spacer(),
// Text(
// '0.0 gd',
// textAlign: TextAlign.center,
// style: TextStyle(color: isDefault ? Colors.white : Colors.black),
// ),
2022-09-11 13:14:52 +02:00
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
balance(
context, address, 16, isDefault ? Colors.white : Colors.black),
])
]),
),
);
}
}