import 'dart:async'; import 'dart:convert' as convert; import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_model.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class WithdrawBloc extends BlocBase { WithdrawModel _model; StreamController _dataController = StreamController(); Stream get outData => _dataController.stream; @override void dispose() { _dataController.close(); _dataController = null; } void loadData(String skipIdentifier) async { NetUtil.request('/api/v1/mod/${skipIdentifier.toString()}', method: NetMethod.GET, onCache: (data) { _loadData(data); }, onSuccess: (data) { _loadData(data); }); } void _loadData(dynamic data) { try { Map json = Map.from(data); if (json == null || json.length == 0) { return; } List mods = json['mod_list']; if (mods.first != null) { json = Map.from(mods.first); String d = json['data']; if (json.containsKey('data')) { String d = json['data']; Map da = Map.from(convert.jsonDecode(d)); _model = WithdrawModel.fromJson(da); _dataController.add(_model); } } } catch (err) { Logger.error(err); } } }