import 'dart:convert';

import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.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.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 GoodsListCreater extends WidgetCreater {
  @override
  List<Widget> createWidgets(Map<String, dynamic> model) {
    print('创建商品列表');
    // final EventBus _eventBus = EventBus();
    final EventBus _eventBus = model['eventBus'];
    Widget _widget = BlocProvider<HomeGoodsHeaderBloc>(bloc: HomeGoodsHeaderBloc(), child: HomeGoodsHeader(model, _eventBus));
    Map<String, dynamic> json = jsonDecode(model['data']);

    return [
      SliverToBoxAdapter(child: Container(margin: EdgeInsets.only(top: ParseUtil.stringParseDouble(null != json ? json['top_margin'] : '0')))),
      SliverPersistentHeader(pinned: true, floating: false, delegate: HomeGoodsHeaderDelegate(_widget)),
      HomeGoods(model, eventBus: _eventBus),
    ];
  }

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

class HomeGoodsHeaderEvent {
  String provider;

  HomeGoodsHeaderEvent(this.provider);
}
