

import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/util/log/let_log.dart';
import 'package:zhiying_comm/util/net_util.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'model/account_delete_page_model.dart';
import 'package:provider/provider.dart';

class AccountDeletePageBloc extends BlocBase{

  AccountDeletePageModel _style;
  Map<String, dynamic> securityStatus;

  StreamController<AccountDeletePageModel> _styleController = StreamController<AccountDeletePageModel>.broadcast();

  Stream<AccountDeletePageModel> get outData => _styleController.stream;

  @override
  void dispose() {
    // TODO: implement dispose
  }

  loadData(String skipIdentifier){
    NetUtil.request('/api/v1/mod/${skipIdentifier.toString()}',onSuccess: (data){
      Logger.log(json.encode(data));
      var mob=data['mod_list'][0];
      _style=AccountDeletePageModel.fromJson(json.decode(mob['data']));
      _styleController.add(_style);
    });
  }

  deleteAccount(BuildContext context) async {
    NetUtil.request("/api/v1/user/delete",method: NetMethod.POST,onSuccess: (data) async {
      Logger.debug('退出登录');
      await Provider.of<UserInfoNotifier>(context, listen: false).unLogin();
      await showDialog(context: context,child: TipDialog(content: "账号注销成功",));
      Navigator.pop(context,true);
    },onError: (e){
      showDialog(context: context,child: TipDialog(content: "账号注销失败!"+e.toString(),));
    });
  }
  
}