Skip to content

Commit 700d917

Browse files
aniketamborethunderbiscuit
authored andcommitted
[Tutorial] Updated exploring bdk flutter tutorial
1 parent 6731323 commit 700d917

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

docs/tutorials/exploring_bdk_flutter.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Once done the file structure should look like this:
100100
101101
import 'package:bdk_flutter_quickstart/screens/home.dart';
102102
import 'package:bdk_flutter_quickstart/styles/theme.dart';
103-
import 'package: flutter/material.dart';
103+
import 'package:flutter/material.dart';
104104
105105
void main() {
106106
runApp(const MyApp());
@@ -282,7 +282,7 @@ class _HomeState extends State<Home> {
282282
late Blockchain blockchain;
283283
TextEditingController mnemonic = TextEditingController();
284284
285-
generateMnemonicHandler() async {
285+
Future<void> generateMnemonicHandler() async {
286286
var res = await Mnemonic.create(WordCount.Words12);
287287
setState(() {
288288
mnemonic.text = res.asString();
@@ -299,7 +299,7 @@ class _HomeState extends State<Home> {
299299
child: Container(
300300
padding: const EdgeInsets.symmetric(horizontal: 30),
301301
child: Column(
302-
children: const [
302+
children: [
303303
/* Balance */
304304
305305
/* Result */
@@ -349,7 +349,7 @@ String? displayText;
349349
350350
// modify the generateMnemonicHandler method to also set mnemonic as displayText
351351
352-
generateMnemonicHandler() async {
352+
Future<void> generateMnemonicHandler() async {
353353
var res = await Mnemonic.create(WordCount.Words12);
354354
setState(() {
355355
mnemonic.text = res.asString();
@@ -418,9 +418,11 @@ Future<List<Descriptor>> getDescriptors(String mnemonic) async {
418418
network: Network.Testnet,
419419
mnemonic: mnemonicObj,
420420
);
421-
final secretKey = descriptorSecretKey.asString();
422421
final descriptor = await Descriptor.newBip84(
423-
secretKey: secretKey, network: Network.Testnet, keyChainKind: e);
422+
secretKey: descriptorSecretKey,
423+
network: Network.Testnet,
424+
keychain: e,
425+
);
424426
descriptors.add(descriptor);
425427
}
426428
return descriptors;
@@ -440,16 +442,16 @@ To create a wallet with `bdk-flutter` call the `create` constructor with `descri
440442
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.
441443

442444
```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 {
445447
try {
446448
final descriptors = await getDescriptors(mnemonic);
447449
final res = await Wallet.create(
448450
descriptor: descriptors[0],
449451
changeDescriptor: descriptors[1],
450452
network: network,
451453
databaseConfig: const DatabaseConfig.memory());
452-
var addressInfo = await res.getAddress(addressIndex: AddressIndex.New);
454+
var addressInfo = await res.getAddress(addressIndex: const AddressIndex());
453455
setState(() {
454456
address = addressInfo.address;
455457
wallet = res;
@@ -471,12 +473,11 @@ Let's add a new button just below the mnemonic `TextFieldContainer`
471473
SubmitButton(
472474
text: "Create Wallet",
473475
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+
);
480481
},
481482
),
482483
```
@@ -492,7 +493,7 @@ Before going forward, we need to create a `Blockchain` object as well. The Block
492493
Let's add an internal method to create and initialize the `Blockchain` object.
493494

494495
```dart
495-
blockchainInit() async {
496+
Future<void> blockchainInit() async {
496497
blockchain = await Blockchain.create(
497498
config: BlockchainConfig.electrum(
498499
config: ElectrumConfig(
@@ -551,7 +552,7 @@ Earlier we have already added a variable for `balance`. Now we will add buttons
551552
Let's add two internal functions for syncing UTXOs and compute balance.
552553

553554
```dart
554-
getBalance() async {
555+
Future<void> getBalance() async {
555556
final balanceObj = await wallet.getBalance();
556557
final res = "Total Balance: ${balanceObj.total.toString()}";
557558
print(res);
@@ -561,7 +562,7 @@ Let's add two internal functions for syncing UTXOs and compute balance.
561562
});
562563
}
563564
564-
syncWallet() async {
565+
Future<void> syncWallet() async {
565566
wallet.sync(blockchain);
566567
}
567568
@@ -578,8 +579,8 @@ Let's use the `address` variable that was created before for this, we need to ad
578579
Add a new `getNewAddress` function below the `syncWallet()` function:
579580

580581
```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());
583584
setState(() {
584585
displayText = res.address;
585586
address = res.address;
@@ -659,7 +660,7 @@ We will need textfield controllers for the recipient address, amount, and for tr
659660
Let's make an internal function to send a bitcoin transaction, using `Wallet`, `Blockchain` and `TxBuilder `.
660661

661662
```dart
662-
sendTx(String addressStr, int amount) async {
663+
Future<void> sendTx(String addressStr, int amount) async {
663664
try {
664665
final txBuilder = TxBuilder();
665666
final address = await Address.create(address: addressStr);

0 commit comments

Comments
 (0)