zoukankan      html  css  js  c++  java
  • json_rpc_2 implementation

    https://stackoverflow.com/questions/52670255/flutter-json-rpc-2-implementation

    import 'dart:convert';
    
    import 'package:flutter/material.dart';
    import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
    import 'package:web_socket_channel/io.dart';
    
    class SymbolDetails extends StatelessWidget {
      final String symbolId;
    
      SymbolDetails({this.symbolId});
    
      @override
      Widget build(BuildContext context) {
        var _api = IOWebSocketChannel.connect('wss://api.hitbtc.com/api/2/ws');
        var client = json_rpc.Client(_api.cast());
        client.sendNotification(
          'subscribeTicker',
          {'symbol': '$symbolId'},
        );
        return Scaffold(
          appBar: AppBar(
            title: Text('$symbolId details'),
          ),
          body: StreamBuilder(
            stream: _api.stream,
            builder: (BuildContext context, AsyncSnapshot snapshot) {
              if (snapshot.connectionState == ConnectionState.none) {
                return Center(
                  child: Text('Please check your internet connection'),
                );
              } else if (!snapshot.hasData) {
                return Center(child: CircularProgressIndicator());
              }
              String _snapshotData = snapshot.data;
              Map _response = json.decode(_snapshotData);
              return ListView(
                children: [
                  ListTile(
                    title: Text('Ask price:'),
                    trailing: Text(
                      '${_response['params']['ask']}',
                      style: TextStyle(fontWeight: FontWeight.bold),
                    ),
                  ),
                  ListTile(
                    title: Text('Bid price:'),
                    trailing: Text(
                      '${_response['params']['bid']}',
                      style: TextStyle(fontWeight: FontWeight.bold),
                    ),
                  ),
                ],
              );
            },
          ),
        );
      }
    }
    

      

     

  • 相关阅读:
    form组件进阶_django
    form组件_django
    django的数据库ORM进阶操作
    内网安装python模块_python
    Redhat7.4安装oracle11.2.0.4版本数据库遇见的问题_oracle
    Redis基础数据类型与对象
    SpringIOC容器——ApplicationContext和BeanFactory
    AQS源码解析
    Java内存模型(一)
    面试准备笔记
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10903725.html
Copyright © 2011-2022 走看看