import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data_sk.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data_widget.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_bloc.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart';
import 'package:zhiying_comm/util/base_bloc.dart';

class MineDataContainer extends StatefulWidget {
  final Map<String, dynamic> data;

  const MineDataContainer(this.data, {Key key}) : super(key: key);

  @override
  _MineDataContainerState createState() => _MineDataContainerState();
}

class _MineDataContainerState extends State<MineDataContainer> {
  MineHeaderBloc _bloc;

  @override
  void initState() {
    _bloc = BlocProvider.of<MineHeaderBloc>(context);
    _bloc.loadData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<MineProfileModel>(
        stream: _bloc.outData,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          MineProfileModel profile = snapshot.data;
          return profile == null
              ? MineDataSkeleton()
              : MineDataWidget(profile, widget.data);
        });
  }
}
