gecko/lib/screens/myWallets/choose_chest.dart

151 lines
5.5 KiB
Dart
Raw Normal View History

2021-11-09 04:22:04 +01:00
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
2021-11-14 19:21:20 +01:00
import 'package:gecko/models/my_wallets.dart';
import 'package:gecko/models/wallet_data.dart';
2021-11-14 19:21:20 +01:00
import 'package:gecko/screens/common_elements.dart';
2021-11-09 04:22:04 +01:00
import 'package:flutter/material.dart';
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
import 'package:gecko/screens/onBoarding/1.dart';
import 'package:carousel_slider/carousel_slider.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();
}
}
2021-11-09 04:22:04 +01:00
// ignore: must_be_immutable
class _ChooseChestState extends State<ChooseChest> {
2021-11-09 04:22:04 +01:00
TextEditingController tplController = TextEditingController();
CarouselController buttonCarouselController = CarouselController();
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(
appBar: AppBar(
2021-11-15 04:16:25 +01:00
toolbarHeight: 60 * ratio,
2021-11-14 19:21:20 +01:00
title: const SizedBox(
2021-11-15 04:16:25 +01:00
height: 22,
child: Text('Sélectionner mon coffre'),
)),
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) {
currentChest = index;
setState(() {});
},
enableInfiniteScroll: false,
initialPage: currentChest,
enlargeCenterPage: true,
viewportFraction: 0.6,
2021-11-09 04:22:04 +01:00
),
items: chestBox.toMap().entries.map((i) {
return Builder(
builder: (BuildContext context) {
return Column(children: <Widget>[
Image.asset(
'assets/chests/${i.value.imageName}',
2021-11-15 03:55:08 +01:00
height: 150,
),
2021-11-14 19:21:20 +01:00
const SizedBox(height: 30),
Text(
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
),
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(
primary: orangeC, // background
2021-11-09 04:22:04 +01:00
onPrimary: Colors.black, // foreground
),
onPressed: () {
configBox.put('currentChest', currentChest);
2021-11-15 03:55:08 +01:00
WalletData defaultWallet =
_myWalletProvider.getDefaultWallet(currentChest);
_myWalletProvider.rebuildWidget();
Navigator.pushAndRemoveUntil(context,
MaterialPageRoute(builder: (context) {
return UnlockingWallet(
wallet: defaultWallet,
action: "mywallets",
);
}), ModalRoute.withName('/'));
2021-11-09 04:22:04 +01:00
},
child: Text(
'Ouvrir ce coffre',
style: TextStyle(
fontSize: 22,
color: backgroundColor,
fontWeight: FontWeight.w600),
),
),
),
2021-11-14 19:21:20 +01:00
const SizedBox(height: 20),
InkWell(
2021-11-14 19:21:20 +01:00
key: const Key('createNewChest'),
2021-11-09 04:22:04 +01:00
onTap: () {
Navigator.push(
2021-11-09 04:22:04 +01:00
context,
FaderTransition(page: OnboardingStepOne(), isFast: false),
2021-11-09 04:22:04 +01:00
);
},
child: SizedBox(
width: 400,
height: 70,
child: Center(
child: Text('Créer un nouveau coffre',
style: TextStyle(
fontSize: 22,
color: orangeC,
fontWeight: FontWeight.w600))),
)),
2021-11-14 19:21:20 +01:00
const SizedBox(height: 10),
2021-11-09 04:22:04 +01:00
]),
));
}
}