@@ -100,7 +100,7 @@ Once done the file structure should look like this:
100
100
101
101
import 'package:bdk_flutter_quickstart/screens/home.dart';
102
102
import 'package:bdk_flutter_quickstart/styles/theme.dart';
103
- import 'package: flutter/material.dart';
103
+ import 'package:flutter/material.dart';
104
104
105
105
void main() {
106
106
runApp(const MyApp());
@@ -282,7 +282,7 @@ class _HomeState extends State<Home> {
282
282
late Blockchain blockchain;
283
283
TextEditingController mnemonic = TextEditingController();
284
284
285
- generateMnemonicHandler() async {
285
+ Future<void> generateMnemonicHandler() async {
286
286
var res = await Mnemonic.create(WordCount.Words12);
287
287
setState(() {
288
288
mnemonic.text = res.asString();
@@ -299,7 +299,7 @@ class _HomeState extends State<Home> {
299
299
child: Container(
300
300
padding: const EdgeInsets.symmetric(horizontal: 30),
301
301
child: Column(
302
- children: const [
302
+ children: [
303
303
/* Balance */
304
304
305
305
/* Result */
@@ -349,7 +349,7 @@ String? displayText;
349
349
350
350
// modify the generateMnemonicHandler method to also set mnemonic as displayText
351
351
352
- generateMnemonicHandler() async {
352
+ Future<void> generateMnemonicHandler() async {
353
353
var res = await Mnemonic.create(WordCount.Words12);
354
354
setState(() {
355
355
mnemonic.text = res.asString();
@@ -418,9 +418,11 @@ Future<List<Descriptor>> getDescriptors(String mnemonic) async {
418
418
network: Network.Testnet,
419
419
mnemonic: mnemonicObj,
420
420
);
421
- final secretKey = descriptorSecretKey.asString();
422
421
final descriptor = await Descriptor.newBip84(
423
- secretKey: secretKey, network: Network.Testnet, keyChainKind: e);
422
+ secretKey: descriptorSecretKey,
423
+ network: Network.Testnet,
424
+ keychain: e,
425
+ );
424
426
descriptors.add(descriptor);
425
427
}
426
428
return descriptors;
@@ -440,16 +442,16 @@ To create a wallet with `bdk-flutter` call the `create` constructor with `descri
440
442
Following our pattern of a button, click handler and bdk-flutter API call, Let's add an internal method which will serve as the click handler for the "Create Wallet" button. We want to see the output of this call so let's use ` setState() ` to set the ` wallet ` object created and the ` displayText ` variable with the wallet's first receive address.
441
443
442
444
``` dart
443
- createOrRestoreWallet(
444
- String mnemonic, Network network, String? password, String path ) async {
445
+ Future<void> createOrRestoreWallet(
446
+ String mnemonic, Network network, String? password) async {
445
447
try {
446
448
final descriptors = await getDescriptors(mnemonic);
447
449
final res = await Wallet.create(
448
450
descriptor: descriptors[0],
449
451
changeDescriptor: descriptors[1],
450
452
network: network,
451
453
databaseConfig: const DatabaseConfig.memory());
452
- var addressInfo = await res.getAddress(addressIndex: AddressIndex.New );
454
+ var addressInfo = await res.getAddress(addressIndex: const AddressIndex() );
453
455
setState(() {
454
456
address = addressInfo.address;
455
457
wallet = res;
@@ -471,12 +473,11 @@ Let's add a new button just below the mnemonic `TextFieldContainer`
471
473
SubmitButton(
472
474
text: "Create Wallet",
473
475
callback: () async {
474
- final res = await createOrRestoreWallet(mnemonic.text, Network.TESTNET,
475
- "password");
476
- setState(() {
477
- displayText = "Wallet Created: ${wallet?.address ?? "Error"}";
478
- wallet = res;
479
- });
476
+ await createOrRestoreWallet(
477
+ mnemonic.text,
478
+ Network.Testnet,
479
+ "password",
480
+ );
480
481
},
481
482
),
482
483
```
@@ -492,7 +493,7 @@ Before going forward, we need to create a `Blockchain` object as well. The Block
492
493
Let's add an internal method to create and initialize the ` Blockchain ` object.
493
494
494
495
``` dart
495
- blockchainInit() async {
496
+ Future<void> blockchainInit() async {
496
497
blockchain = await Blockchain.create(
497
498
config: BlockchainConfig.electrum(
498
499
config: ElectrumConfig(
@@ -551,7 +552,7 @@ Earlier we have already added a variable for `balance`. Now we will add buttons
551
552
Let's add two internal functions for syncing UTXOs and compute balance.
552
553
553
554
``` dart
554
- getBalance() async {
555
+ Future<void> getBalance() async {
555
556
final balanceObj = await wallet.getBalance();
556
557
final res = "Total Balance: ${balanceObj.total.toString()}";
557
558
print(res);
@@ -561,7 +562,7 @@ Let's add two internal functions for syncing UTXOs and compute balance.
561
562
});
562
563
}
563
564
564
- syncWallet() async {
565
+ Future<void> syncWallet() async {
565
566
wallet.sync(blockchain);
566
567
}
567
568
@@ -578,8 +579,8 @@ Let's use the `address` variable that was created before for this, we need to ad
578
579
Add a new ` getNewAddress ` function below the ` syncWallet() ` function:
579
580
580
581
``` dart
581
- getNewAddress() async {
582
- final res = await wallet.getAddress(addressIndex: AddressIndex.New );
582
+ Future<void> getNewAddress() async {
583
+ final res = await wallet.getAddress(addressIndex: const AddressIndex() );
583
584
setState(() {
584
585
displayText = res.address;
585
586
address = res.address;
@@ -659,7 +660,7 @@ We will need textfield controllers for the recipient address, amount, and for tr
659
660
Let's make an internal function to send a bitcoin transaction, using ` Wallet ` , ` Blockchain ` and ` TxBuilder ` .
660
661
661
662
``` dart
662
- sendTx(String addressStr, int amount) async {
663
+ Future<void> sendTx(String addressStr, int amount) async {
663
664
try {
664
665
final txBuilder = TxBuilder();
665
666
final address = await Address.create(address: addressStr);
0 commit comments