import 'dart:convert' as convert;

import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/goods_details/recommend/goods_detail_commend_list.dart';
import 'package:zhiying_base_widget/widgets/goods_details/recommend/goods_detail_commend_widget.dart';
import 'package:zhiying_base_widget/widgets/goods_details/recommend/models/goods_detail_recommend_model.dart';
import 'package:zhiying_base_widget/widgets/home/home_goods/bloc/home_goods_header_bloc.dart';
import 'package:zhiying_base_widget/widgets/home/home_goods/home_goods_header.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class GoodsDetailCommendCreater extends WidgetCreater {
  final EventBus _eventBus = EventBus();

  @override
  List<Widget> createWidgets(Map<String, dynamic> model) {
    String d = model['data'];
    Map<String, dynamic> json = convert.jsonDecode(d);
    GoodsDetailRecommendModel style = GoodsDetailRecommendModel.fromJson(json);

    print('创建商品列表');
    Widget _widget = BlocProvider<HomeGoodsHeaderBloc>(
      bloc: HomeGoodsHeaderBloc(),
      child: HomeGoodsHeader(model, _eventBus),
    );

    return [
      SliverToBoxAdapter(
        child: GoodsDetailsRecommendWidget(model),
      ),
      SliverToBoxAdapter(
        child: GoodsDetailCommendList(
          model,
          provider: style.recType, // 猜你喜欢数据源暂无数据
        ),
      ),
    ];
  }

  @override
  bool isSliverChild() {
    return true;
  }
}
