import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/widgets/home/home_goods/bloc/home_goods_header_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'custom_goods2.dart';
import 'custom_goods_header2.dart';

class CategoryGoodsListCreater2 extends WidgetCreater {
  @override
  List<Widget> createWidgets(Map<String, dynamic> model) {
    print('创建商品列表');
    Map<String, dynamic> json = {};
    try {
      json = jsonDecode(model['data']);
    } catch (e) {}
    final GlobalKey<CustomGoodsContainer2State> globalKey = GlobalKey();

    Widget padding = SliverToBoxAdapter(child: Container(margin: EdgeInsets.only(top: ParseUtil.stringParseDouble(null != json ? json['top_margin'] : '0'))));
    Widget goodsList = CustomGoods2(model, globalKey: globalKey,);
    Widget _widget = BlocProvider<HomeGoodsHeaderBloc>(bloc: HomeGoodsHeaderBloc(), child: CustomGoodsHeader2(model, globalKey: globalKey,));
    Widget head = SliverPersistentHeader(pinned: true, floating: false, delegate: CustomGoodsHeaderDelegate2(_widget));
    return [
      padding,
      head,
      goodsList,
    ];
  }

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