gecko/lib/screens/myWallets/choose_chest.dart

206 lines
7.5 KiB
Dart
Raw Normal View History

// ignore_for_file: use_build_context_synchronously
2022-06-17 01:13:14 +02:00
import 'package:easy_localization/easy_localization.dart';
2021-11-09 04:22:04 +01:00
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/widgets_keys.dart';
import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/models/wallet_data.dart';
2021-11-09 04:22:04 +01:00
import 'package:flutter/material.dart';
2022-05-25 20:40:55 +02:00
import 'package:gecko/screens/myWallets/restore_chest.dart';
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:gecko/screens/myWallets/wallets_home.dart';
2022-05-25 20:40:55 +02:00
import 'package:gecko/screens/onBoarding/5.dart';
import 'package:provider/provider.dart';
2021-11-09 04:22:04 +01:00
class ChooseChest extends StatefulWidget {
const ChooseChest({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _ChooseChestState();
}
}
class _ChooseChestState extends State<ChooseChest> {
2021-11-09 04:22:04 +01:00
TextEditingController tplController = TextEditingController();
CarouselController buttonCarouselController = CarouselController();
2021-12-23 12:36:09 +01:00
int? currentChest = configBox.get('currentChest');
2021-11-14 19:21:20 +01:00
2021-11-09 04:22:04 +01:00
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
MyWalletsProvider myWalletProvider =
Provider.of<MyWalletsProvider>(context);
2021-11-09 04:22:04 +01:00
return Scaffold(
2022-05-29 00:00:57 +02:00
backgroundColor: backgroundColor,
2021-11-09 04:22:04 +01:00
appBar: AppBar(
2021-11-15 04:16:25 +01:00
toolbarHeight: 60 * ratio,
2022-06-17 01:13:14 +02:00
title: SizedBox(
2021-11-15 04:16:25 +01:00
height: 22,
2022-06-17 01:13:14 +02:00
child: Text('selectMyChest'.tr()),
2021-11-15 04:16:25 +01:00
)),
2021-11-09 04:22:04 +01:00
body: SafeArea(
child: Column(children: <Widget>[
SizedBox(height: 160 * ratio),
CarouselSlider(
carouselController: buttonCarouselController,
options: CarouselOptions(
height: 210,
onPageChanged: (index, reason) {
2021-11-17 06:20:23 +01:00
currentChest = chestBox.toMap().keys.toList()[index];
setState(() {});
},
enableInfiniteScroll: false,
2021-12-23 12:36:09 +01:00
initialPage: currentChest!,
enlargeCenterPage: true,
2021-12-23 21:44:24 +01:00
viewportFraction: 0.5,
2021-11-09 04:22:04 +01:00
),
items: chestBox.toMap().entries.map((i) {
return Builder(
builder: (BuildContext context) {
return Column(children: <Widget>[
2021-11-17 06:20:23 +01:00
i.value.imageFile == null
? Image.asset(
'assets/chests/${i.value.imageName}',
height: 150,
)
: Image.file(
2021-12-23 12:36:09 +01:00
i.value.imageFile!,
2021-11-17 06:20:23 +01:00
height: 150,
),
2021-11-14 19:21:20 +01:00
const SizedBox(height: 30),
Text(
2021-12-23 12:36:09 +01:00
i.value.name!,
2021-11-14 19:21:20 +01:00
style: const TextStyle(fontSize: 21),
),
]);
},
);
}).toList(),
2021-11-09 04:22:04 +01:00
),
2021-11-17 06:20:23 +01:00
if (chestBox.values.toList().length > 1)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: chestBox.toMap().entries.map((entry) {
return GestureDetector(
onTap: () =>
buttonCarouselController.animateToPage(entry.key),
child: Container(
width: 12.0,
height: 12.0,
margin: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 4.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
(Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black)
.withOpacity(
currentChest == entry.key ? 0.9 : 0.4)),
),
);
}).toList(),
),
SizedBox(height: 80 * ratio),
SizedBox(
width: 400,
height: 70,
child: ElevatedButton(
2021-11-09 04:22:04 +01:00
style: ElevatedButton.styleFrom(
2022-09-05 08:12:24 +02:00
foregroundColor: Colors.black,
backgroundColor: orangeC, // foreground
2021-11-09 04:22:04 +01:00
),
onPressed: () async {
await configBox.put('currentChest', currentChest);
myWalletProvider.pinCode = '';
2021-12-23 12:36:09 +01:00
WalletData? defaultWallet =
myWalletProvider.getDefaultWallet();
2022-09-09 01:12:17 +02:00
myWalletProvider.reload();
await Navigator.push(
context,
MaterialPageRoute(
builder: (homeContext) {
return UnlockingWallet(wallet: defaultWallet);
},
),
);
Navigator.popUntil(
context,
ModalRoute.withName('/'),
);
if (myWalletProvider.pinCode != '') {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const WalletsHome();
}),
);
}
2021-11-09 04:22:04 +01:00
},
child: Text(
2022-06-17 01:13:14 +02:00
'openThisChest'.tr(),
2022-09-12 12:38:32 +02:00
style: const TextStyle(
fontSize: 22,
color: backgroundColor,
fontWeight: FontWeight.w600),
),
),
),
2022-05-25 20:40:55 +02:00
// const SizedBox(height: 20),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: InkWell(
key: keyCreateNewChest,
2022-05-25 20:40:55 +02:00
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const OnboardingStepFive(skipIntro: true);
}),
);
},
child: SizedBox(
width: 400,
height: 50,
child: Center(
2022-06-17 01:13:14 +02:00
child: Text('createChest'.tr(),
2022-09-12 12:38:32 +02:00
style: const TextStyle(
2022-05-25 20:40:55 +02:00
fontSize: 22,
color: orangeC,
fontWeight: FontWeight.w600))),
),
),
),
),
InkWell(
key: keyImportChest,
2021-11-09 04:22:04 +01:00
onTap: () {
Navigator.push(
2021-11-09 04:22:04 +01:00
context,
MaterialPageRoute(builder: (context) {
2022-05-25 20:40:55 +02:00
return const RestoreChest(skipIntro: true);
}),
2021-11-09 04:22:04 +01:00
);
},
child: SizedBox(
width: 400,
2022-05-25 20:40:55 +02:00
height: 50,
child: Center(
2022-06-17 01:13:14 +02:00
child: Text('importChest'.tr(),
2022-09-12 12:38:32 +02:00
style: const TextStyle(
fontSize: 22,
color: orangeC,
fontWeight: FontWeight.w600))),
)),
2022-05-25 20:40:55 +02:00
const SizedBox(height: 20),
2021-11-09 04:22:04 +01:00
]),
));
}
}