2021-11-09 04:22:04 +01:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:gecko/globals.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
2021-11-15 00:39:40 +01:00
|
|
|
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';
|
2021-11-15 00:39:40 +01:00
|
|
|
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
2021-11-14 03:12:07 +01:00
|
|
|
import 'package:carousel_slider/carousel_slider.dart';
|
2022-05-25 20:40:55 +02:00
|
|
|
import 'package:gecko/screens/onBoarding/5.dart';
|
2021-11-14 03:12:07 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2021-11-09 04:22:04 +01:00
|
|
|
|
2021-11-15 00:39:40 +01:00
|
|
|
class ChooseChest extends StatefulWidget {
|
2021-12-23 12:36:09 +01:00
|
|
|
const ChooseChest({this.action, Key? key}) : super(key: key);
|
|
|
|
final String? action;
|
2021-11-15 00:39:40 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _ChooseChestState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 04:22:04 +01:00
|
|
|
// ignore: must_be_immutable
|
2021-11-15 00:39:40 +01:00
|
|
|
class _ChooseChestState extends State<ChooseChest> {
|
2021-11-09 04:22:04 +01:00
|
|
|
TextEditingController tplController = TextEditingController();
|
2021-11-14 03:12:07 +01:00
|
|
|
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]);
|
2021-11-14 03:12:07 +01:00
|
|
|
MyWalletsProvider _myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
|
|
|
|
2021-12-03 10:25:36 +01:00
|
|
|
log.d(widget.action);
|
|
|
|
|
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,
|
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>[
|
2021-11-15 00:39:40 +01:00
|
|
|
SizedBox(height: 160 * ratio),
|
2021-11-14 03:12:07 +01:00
|
|
|
CarouselSlider(
|
|
|
|
carouselController: buttonCarouselController,
|
|
|
|
options: CarouselOptions(
|
|
|
|
height: 210,
|
|
|
|
onPageChanged: (index, reason) {
|
2021-11-17 06:20:23 +01:00
|
|
|
currentChest = chestBox.toMap().keys.toList()[index];
|
2021-11-15 00:39:40 +01:00
|
|
|
setState(() {});
|
2021-11-14 03:12:07 +01:00
|
|
|
},
|
|
|
|
enableInfiniteScroll: false,
|
2021-12-23 12:36:09 +01:00
|
|
|
initialPage: currentChest!,
|
2021-11-14 03:12:07 +01:00
|
|
|
enlargeCenterPage: true,
|
2021-12-23 21:44:24 +01:00
|
|
|
viewportFraction: 0.5,
|
2021-11-09 04:22:04 +01:00
|
|
|
),
|
2021-11-14 03:12:07 +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),
|
2021-11-14 03:12:07 +01:00
|
|
|
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),
|
2021-11-14 03:12:07 +01:00
|
|
|
),
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}).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(),
|
|
|
|
),
|
2021-11-15 00:39:40 +01:00
|
|
|
SizedBox(height: 80 * ratio),
|
2021-11-12 01:32:05 +01:00
|
|
|
SizedBox(
|
|
|
|
width: 400,
|
|
|
|
height: 70,
|
|
|
|
child: ElevatedButton(
|
2021-11-09 04:22:04 +01:00
|
|
|
style: ElevatedButton.styleFrom(
|
2021-11-12 01:32:05 +01:00
|
|
|
primary: orangeC, // background
|
2021-11-09 04:22:04 +01:00
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: () {
|
2021-11-14 03:12:07 +01:00
|
|
|
configBox.put('currentChest', currentChest);
|
2021-12-23 12:36:09 +01:00
|
|
|
WalletData? defaultWallet =
|
2022-05-26 02:19:29 +02:00
|
|
|
_myWalletProvider.getDefaultWallet();
|
2021-11-14 03:12:07 +01:00
|
|
|
_myWalletProvider.rebuildWidget();
|
2021-12-02 07:23:12 +01:00
|
|
|
Navigator.pushAndRemoveUntil(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return UnlockingWallet(
|
|
|
|
wallet: defaultWallet,
|
2021-12-03 10:25:36 +01:00
|
|
|
action: widget.action ?? "mywallets",
|
2021-12-02 07:23:12 +01:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
ModalRoute.withName('/'),
|
|
|
|
);
|
2021-11-09 04:22:04 +01:00
|
|
|
},
|
2021-11-12 01:32:05 +01:00
|
|
|
child: Text(
|
|
|
|
'Ouvrir ce coffre',
|
|
|
|
style: 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: const Key('createNewChest'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return const OnboardingStepFive(skipIntro: true);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: SizedBox(
|
|
|
|
width: 400,
|
|
|
|
height: 50,
|
|
|
|
child: Center(
|
|
|
|
child: Text('Créer un nouveau coffre',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
color: orangeC,
|
|
|
|
fontWeight: FontWeight.w600))),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-12 01:32:05 +01:00
|
|
|
InkWell(
|
2022-05-25 20:40:55 +02:00
|
|
|
key: const Key('importChest'),
|
2021-11-09 04:22:04 +01:00
|
|
|
onTap: () {
|
2021-11-12 01:32:05 +01:00
|
|
|
Navigator.push(
|
2021-11-09 04:22:04 +01:00
|
|
|
context,
|
2021-11-18 04:41:45 +01:00
|
|
|
MaterialPageRoute(builder: (context) {
|
2022-05-25 20:40:55 +02:00
|
|
|
return const RestoreChest(skipIntro: true);
|
2021-11-18 04:41:45 +01:00
|
|
|
}),
|
2021-11-09 04:22:04 +01:00
|
|
|
);
|
|
|
|
},
|
2021-11-12 01:32:05 +01:00
|
|
|
child: SizedBox(
|
|
|
|
width: 400,
|
2022-05-25 20:40:55 +02:00
|
|
|
height: 50,
|
2021-11-12 01:32:05 +01:00
|
|
|
child: Center(
|
2022-05-25 20:40:55 +02:00
|
|
|
child: Text('Importer un coffre',
|
2021-11-12 01:32:05 +01:00
|
|
|
style: 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
|
|
|
]),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|