123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:polkawallet_sdk/polkawallet_sdk.dart';
- import 'package:polkawallet_sdk_example/pages/keyring.dart';
- class SettingPage extends StatefulWidget {
- SettingPage(this.sdk, this.showResult);
- final WalletSDK sdk;
- final Function(BuildContext, String, String) showResult;
- static const String route = '/setting';
- @override
- _SettingPageState createState() => _SettingPageState();
- }
- class _SettingPageState extends State<SettingPage> {
- bool _submitting = false;
- BigInt? _bestNumber;
- Future<void> _queryNetworkConst() async {
- setState(() {
- _submitting = true;
- });
- final res = await widget.sdk.api.setting.queryNetworkConst();
- widget.showResult(
- context,
- 'queryNetworkConst',
- JsonEncoder.withIndent(' ').convert(res),
- );
- setState(() {
- _submitting = false;
- });
- }
- Future<void> _queryNetworkProperties() async {
- setState(() {
- _submitting = true;
- });
- final res = await widget.sdk.api.setting.queryNetworkProps();
- widget.showResult(
- context,
- 'queryNetworkProps',
- JsonEncoder.withIndent(' ').convert(res?.toJson()),
- );
- setState(() {
- _submitting = false;
- });
- }
- Future<void> _subscribeBestNumber() async {
- widget.sdk.api.setting.subscribeBestNumber((res) {
- setState(() {
- _bestNumber = BigInt.parse(res.toString());
- });
- });
- }
- Future<void> _unsubscribeBestNumber() async {
- widget.sdk.api.setting.unsubscribeBestNumber();
- }
- @override
- void dispose() {
- _unsubscribeBestNumber();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('setting API'),
- ),
- body: SafeArea(
- child: ListView(
- children: [
- Padding(
- padding: EdgeInsets.all(16),
- child: Text('bestNumber: #$_bestNumber'),
- ),
- Divider(),
- ListTile(
- title: Text('queryNetworkConst'),
- subtitle: Text('sdk.api.setting.queryNetworkConst()'),
- trailing: SubmitButton(
- submitting: _submitting,
- call: _queryNetworkConst,
- needConnect: widget.sdk.api.connectedNode == null,
- ),
- ),
- Divider(),
- ListTile(
- title: Text('queryNetworkProps'),
- subtitle: Text('sdk.api.setting.queryNetworkProps()'),
- trailing: SubmitButton(
- submitting: _submitting,
- call: _queryNetworkProperties,
- needConnect: widget.sdk.api.connectedNode == null,
- ),
- ),
- Divider(),
- ListTile(
- title: Text('subscribeBestNumber'),
- subtitle: Text('sdk.api.setting.subscribeBestNumber()'),
- trailing: SubmitButton(
- submitting: _submitting,
- call: _subscribeBestNumber,
- needConnect: widget.sdk.api.connectedNode == null,
- ),
- ),
- Divider(),
- ListTile(
- title: Text('unsubscribeBestNumber'),
- subtitle: Text('sdk.api.setting.unsubscribeBestNumber()'),
- trailing: SubmitButton(
- submitting: _submitting,
- call: _unsubscribeBestNumber,
- needConnect: widget.sdk.api.connectedNode == null,
- ),
- ),
- Divider(),
- ],
- ),
- ), // This trailing comma makes auto-formatting nicer for build methods.
- );
- }
- }
|