gecko/lib/screens/myWallets/change_pin.dart

145 lines
4.7 KiB
Dart
Raw Normal View History

2021-01-15 11:42:05 +01:00
import 'package:flutter/material.dart';
import 'package:dubp/dubp.dart';
2021-02-27 20:29:35 +01:00
import 'package:flutter/services.dart';
2021-11-08 23:12:25 +01:00
import 'package:gecko/globals.dart';
2021-11-14 19:21:20 +01:00
import 'package:gecko/models/change_pin.dart';
2021-11-18 02:37:46 +01:00
import 'package:gecko/models/my_wallets.dart';
2021-01-15 11:42:05 +01:00
import 'dart:io';
import 'package:provider/provider.dart';
2021-01-15 11:42:05 +01:00
// ignore: must_be_immutable
class ChangePinScreen extends StatelessWidget with ChangeNotifier {
ChangePinScreen(
2021-11-18 02:37:46 +01:00
{Key keyMyWallets,
@required this.walletName,
@required this.walletProvider})
2021-01-15 11:42:05 +01:00
: super(key: keyMyWallets);
final String walletName;
2021-11-18 02:37:46 +01:00
final MyWalletsProvider walletProvider;
2021-01-15 11:42:05 +01:00
Directory appPath;
NewWallet _newWalletFile;
2021-01-15 11:42:05 +01:00
@override
Widget build(BuildContext context) {
2021-02-27 20:29:35 +01:00
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
ChangePinProvider _changePin = Provider.of<ChangePinProvider>(context);
// _walletOptions.changePin(walletName, oldPin);
// _walletOptions.newPin.text = _tmpPin;
return WillPopScope(
2021-11-18 02:37:46 +01:00
onWillPop: () {
_changePin.newPin.text = '';
return Future<bool>.value(true);
},
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
2021-11-21 06:36:12 +01:00
toolbarHeight: 60 * ratio,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.black),
onPressed: () {
_changePin.newPin.text = '';
Navigator.of(context).pop();
}),
title: SizedBox(
height: 22,
child: Text(walletName),
),
),
2021-11-18 02:37:46 +01:00
body: Center(
child: SafeArea(
child: Column(children: <Widget>[
StatefulWrapper(
onInit: () async {
_newWalletFile =
await _changePin.changePin(walletProvider.pinCode);
},
child: Container(),
),
2021-11-14 19:21:20 +01:00
const SizedBox(height: 80),
Text(
'Choisissez un code secret autogénéré :',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 17.0,
color: Colors.grey[600],
fontWeight: FontWeight.w400),
),
2021-11-14 19:21:20 +01:00
const SizedBox(height: 30),
Stack(
alignment: Alignment.centerRight,
children: <Widget>[
TextField(
2021-11-18 02:37:46 +01:00
enabled: false,
2021-11-14 19:21:20 +01:00
controller: _changePin.newPin,
maxLines: 1,
textAlign: TextAlign.center,
decoration: const InputDecoration(),
style: const TextStyle(
fontSize: 30.0,
color: Colors.black,
fontWeight: FontWeight.bold)),
IconButton(
icon: const Icon(Icons.replay),
color: orangeC,
onPressed: () async {
_newWalletFile =
2021-11-18 02:37:46 +01:00
await _changePin.changePin(walletProvider.pinCode);
2021-11-14 19:21:20 +01:00
},
),
],
),
2021-11-14 19:21:20 +01:00
const SizedBox(height: 30),
SizedBox(
width: 200,
height: 50,
child: ElevatedButton(
2021-11-18 02:37:46 +01:00
style: ElevatedButton.styleFrom(
elevation: 12,
primary: Colors.green[400], //smoothYellow, // background
onPrimary: Colors.black, // foreground
),
onPressed: _changePin.newPin.text != ''
? () {
_changePin.newPin.text = '';
_changePin.storeNewPinChest(context, _newWalletFile);
walletProvider.pinCode = _changePin.newPin.text;
}
: null,
child: const Text(
'Confirmer',
style: TextStyle(fontSize: 28),
),
),
)
2021-11-18 02:37:46 +01:00
]),
),
),
),
);
2021-01-15 11:42:05 +01:00
}
}
class StatefulWrapper extends StatefulWidget {
final Function onInit;
final Widget child;
const StatefulWrapper({Key key, @required this.onInit, @required this.child})
: super(key: key);
@override
_StatefulWrapperState createState() => _StatefulWrapperState();
}
class _StatefulWrapperState extends State<StatefulWrapper> {
@override
void initState() {
if (widget.onInit != null) {
widget.onInit();
}
super.initState();
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}