json_rpc_2 implementation

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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),
                ),
              ),
            ],
          );
        },
      ),
    );
  }
}

  

 

posted @ 2019-05-22 08:35  CrossPython  阅读(380)  评论(0)    收藏  举报
编辑推荐:
· AES 加密模式演进:从 ECB、CBC 到 GCM 的 C# 深度实践
· InnoDB为什么不用跳表,Redis为什么不用B+树?
· 记一次 C# 平台调用中因非托管 union 类型导致的内存访问越界
· [EF Core]聊聊“复合”属性
· 那些被推迟的 C# 14 特性及其背后的故事
阅读排行:
· 博客园出海记-开篇:扬帆启航
· 关于布尔类型的变量不要加 is 前缀,被网友们吐槽了,特来完善下
· 30 岁 Java 仍在 “霸榜“:开发者凭什么还在为它熬夜?
· GPT5写5000行代码,行不行?
· 扣子(Coze),开源了!Dify 天塌了
点击右上角即可分享
微信分享提示