Skip to content
Snippets Groups Projects
walletsHome.dart 6.24 KiB
Newer Older
poka's avatar
poka committed
import 'package:gecko/models/myWallets.dart';
import 'package:gecko/models/walletOptions.dart';
import 'package:gecko/screens/myWallets/generateWallets.dart';
import 'package:flutter/material.dart';
import 'package:gecko/screens/myWallets/walletOptions.dart';
import 'package:provider/provider.dart';
poka's avatar
poka committed
// ignore: must_be_immutable
class WalletsHome extends StatelessWidget {
poka's avatar
poka committed
  final _derivationKey = GlobalKey<FormState>();
  final TextEditingController _newDerivationName = TextEditingController();

  @override
  Widget build(BuildContext context) {
    MyWalletsProvider myWalletProvider =
        Provider.of<MyWalletsProvider>(context);
    WalletOptionsProvider _walletOptions =
        Provider.of<WalletOptionsProvider>(context);
    _walletOptions.isWalletUnlock = false;
poka's avatar
poka committed
    myWalletProvider.listWallets = myWalletProvider.getAllWalletsNames();
    final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
poka's avatar
poka committed

    return Scaffold(
        floatingActionButton: Visibility(
            child: Container(
                height: 80.0,
                width: 80.0,
                child: FittedBox(
                    child: FloatingActionButton(
                        heroTag: "buttonGenerateWallet",
                        onPressed: () {
poka's avatar
poka committed
                          showDialog(
                              context: context,
                              builder: (BuildContext context) {
                                return addNewDerivation(context, 1);
                              });
                        },
                        child: Container(
                            height: 40.0,
                            width: 40.0,
                            child: Icon(Icons.person_add_alt_1_rounded,
                                color: Colors.grey[850])),
                        backgroundColor: Color(0xffEFEFBF))))),
        body: SafeArea(
            child: Column(children: <Widget>[
          Visibility(
              child: Column(children: <Widget>[
                SizedBox(height: 120),
                Center(
                    child: Text("Vous n'avez encore généré aucun portefeuille.",
                        style: TextStyle(
                            fontSize: 20, fontWeight: FontWeight.w500),
                        textAlign: TextAlign.center)),
                SizedBox(height: 80),
                ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      primary: Color(0xffFFD68E), // background
                      onPrimary: Colors.black, // foreground
                    ),
                    onPressed: () => Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) {
                            return GenerateWalletsScreen();
                          }),
poka's avatar
poka committed
                        ),
                    child: Text('Générer un trousseau',
                        style: TextStyle(fontSize: 20))),
                SizedBox(height: 15),
                Center(
                    child: Text("ou",
                        style: TextStyle(
                            fontSize: 20, fontWeight: FontWeight.w500),
                        textAlign: TextAlign.center)),
                SizedBox(height: 15),
                ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      primary: Color(0xffFFD68E), // background
                      onPrimary: Colors.black, // foreground
                    ),
poka's avatar
poka committed
                    onPressed: () => myWalletProvider.importWallet(),
                    child: Text('Importer un portefeuille existant',
                        style: TextStyle(fontSize: 20))),
              ])),
          Visibility(visible: isWalletsExists, child: myWalletsList(context))
  Widget myWalletsList(BuildContext context) {
    MyWalletsProvider myWalletProvider =
        Provider.of<MyWalletsProvider>(context);
poka's avatar
poka committed
    List _listWallets = myWalletProvider.listWallets.split('\n');
poka's avatar
poka committed
    return Expanded(
        child: ListView(children: <Widget>[
poka's avatar
poka committed
      SizedBox(height: 8),
poka's avatar
poka committed
        ListTile(
          contentPadding: const EdgeInsets.all(5.0),
          leading: Padding(
              padding: const EdgeInsets.all(15.0),
              child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))),
          title:
              Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)),
poka's avatar
poka committed
          dense: true,
          onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (context) {
              return WalletOptions(
                  walletNbr: int.parse(_repository.split(':')[0]),
poka's avatar
poka committed
                  walletName: _repository.split(':')[1],
                  derivation: int.parse(_repository.split(':')[2]));
poka's avatar
poka committed
            }));
          },
poka's avatar
poka committed
    ]));
poka's avatar
poka committed
  }
poka's avatar
poka committed

  Widget addNewDerivation(context, int _walletNbr) {
    MyWalletsProvider _myWalletProvider =
        Provider.of<MyWalletsProvider>(context);
    return AlertDialog(
      content: Stack(
        overflow: Overflow.visible,
        children: <Widget>[
          Form(
            key: _derivationKey,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Text('Nom du portefeuille:'),
                Padding(
                  padding: EdgeInsets.all(8.0),
                  child: TextFormField(
                    controller: _newDerivationName,
                    textAlign: TextAlign.center,
                    autofocus: true,
                  ),
                ),
                SizedBox(height: 20),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    child: Text("Créer"),
                    color: Color(0xffFFD68E),
                    onPressed: () async {
                      await _myWalletProvider
                          .generateNewDerivation(
                              context, _newDerivationName.text, _walletNbr)
                          .then((_) => _newDerivationName.text == '');
                    },
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }