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), ), ), ], ); }, ), ); } } |
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
· AES 加密模式演进:从 ECB、CBC 到 GCM 的 C# 深度实践
· InnoDB为什么不用跳表,Redis为什么不用B+树?
· 记一次 C# 平台调用中因非托管 union 类型导致的内存访问越界
· [EF Core]聊聊“复合”属性
· 那些被推迟的 C# 14 特性及其背后的故事
· 博客园出海记-开篇:扬帆启航
· 关于布尔类型的变量不要加 is 前缀,被网友们吐槽了,特来完善下
· 30 岁 Java 仍在 “霸榜“:开发者凭什么还在为它熬夜?
· GPT5写5000行代码,行不行?
· 扣子(Coze),开源了!Dify 天塌了