setting.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:polkawallet_sdk/polkawallet_sdk.dart';
  4. import 'package:polkawallet_sdk_example/pages/keyring.dart';
  5. class SettingPage extends StatefulWidget {
  6. SettingPage(this.sdk, this.showResult);
  7. final WalletSDK sdk;
  8. final Function(BuildContext, String, String) showResult;
  9. static const String route = '/setting';
  10. @override
  11. _SettingPageState createState() => _SettingPageState();
  12. }
  13. class _SettingPageState extends State<SettingPage> {
  14. bool _submitting = false;
  15. BigInt? _bestNumber;
  16. Future<void> _queryNetworkConst() async {
  17. setState(() {
  18. _submitting = true;
  19. });
  20. final res = await widget.sdk.api.setting.queryNetworkConst();
  21. widget.showResult(
  22. context,
  23. 'queryNetworkConst',
  24. JsonEncoder.withIndent(' ').convert(res),
  25. );
  26. setState(() {
  27. _submitting = false;
  28. });
  29. }
  30. Future<void> _queryNetworkProperties() async {
  31. setState(() {
  32. _submitting = true;
  33. });
  34. final res = await widget.sdk.api.setting.queryNetworkProps();
  35. widget.showResult(
  36. context,
  37. 'queryNetworkProps',
  38. JsonEncoder.withIndent(' ').convert(res?.toJson()),
  39. );
  40. setState(() {
  41. _submitting = false;
  42. });
  43. }
  44. Future<void> _subscribeBestNumber() async {
  45. widget.sdk.api.setting.subscribeBestNumber((res) {
  46. setState(() {
  47. _bestNumber = BigInt.parse(res.toString());
  48. });
  49. });
  50. }
  51. Future<void> _unsubscribeBestNumber() async {
  52. widget.sdk.api.setting.unsubscribeBestNumber();
  53. }
  54. @override
  55. void dispose() {
  56. _unsubscribeBestNumber();
  57. super.dispose();
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. return Scaffold(
  62. appBar: AppBar(
  63. title: Text('setting API'),
  64. ),
  65. body: SafeArea(
  66. child: ListView(
  67. children: [
  68. Padding(
  69. padding: EdgeInsets.all(16),
  70. child: Text('bestNumber: #$_bestNumber'),
  71. ),
  72. Divider(),
  73. ListTile(
  74. title: Text('queryNetworkConst'),
  75. subtitle: Text('sdk.api.setting.queryNetworkConst()'),
  76. trailing: SubmitButton(
  77. submitting: _submitting,
  78. call: _queryNetworkConst,
  79. needConnect: widget.sdk.api.connectedNode == null,
  80. ),
  81. ),
  82. Divider(),
  83. ListTile(
  84. title: Text('queryNetworkProps'),
  85. subtitle: Text('sdk.api.setting.queryNetworkProps()'),
  86. trailing: SubmitButton(
  87. submitting: _submitting,
  88. call: _queryNetworkProperties,
  89. needConnect: widget.sdk.api.connectedNode == null,
  90. ),
  91. ),
  92. Divider(),
  93. ListTile(
  94. title: Text('subscribeBestNumber'),
  95. subtitle: Text('sdk.api.setting.subscribeBestNumber()'),
  96. trailing: SubmitButton(
  97. submitting: _submitting,
  98. call: _subscribeBestNumber,
  99. needConnect: widget.sdk.api.connectedNode == null,
  100. ),
  101. ),
  102. Divider(),
  103. ListTile(
  104. title: Text('unsubscribeBestNumber'),
  105. subtitle: Text('sdk.api.setting.unsubscribeBestNumber()'),
  106. trailing: SubmitButton(
  107. submitting: _submitting,
  108. call: _unsubscribeBestNumber,
  109. needConnect: widget.sdk.api.connectedNode == null,
  110. ),
  111. ),
  112. Divider(),
  113. ],
  114. ),
  115. ), // This trailing comma makes auto-formatting nicer for build methods.
  116. );
  117. }
  118. }