import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:zhiying_base_widget/pages/search_page/notifier/search_tag_notifier.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

import 'brand_page_bloc.dart';

///品牌页面

class BrandPage extends StatefulWidget {
  @override
  _BrandPageState createState() => _BrandPageState();
}

class _BrandPageState extends State<BrandPage> {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: [ChangeNotifierProvider.value(value: SearchTagNotifier())],
        child: BlocProvider(child: BrandPageContainer(), bloc: BrandBloc()));
  }
}

class BrandPageContainer extends StatefulWidget {
  @override
  _BrandPageContainerState createState() => _BrandPageContainerState();
}


class _BrandPageContainerState extends State<BrandPageContainer> {

  @override
  void initState() {

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(builder: (context, asyn) {

      var model=asyn.data;
      if(model==null){
        return Container();///骨架图
      }
      return Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text("大牌秒杀",style: TextStyle(color: HexColor.fromHex("#FFFFFF"),fontSize: 17),),
        ),
        body: Container(
          child: Stack(
            children: <Widget>[
              CustomScrollView(
                slivers: _createContent(context, model),
              )
            ],
          ),
        ),
      );
    });
  }
}

///构建子模块
_createContent(BuildContext context, List<Map<String, dynamic>> model) {
  List<Widget> list = List();
  if (model == null) {
    ///骨架图
  } else {
    for (var item in model) {
      WidgetModel widgetModel =
          WidgetModel.fromJson(Map<String, dynamic>.from(item));
      if (item.containsKey("mod_name") &&
          item['mod_name'] == "hot_rank_tab_view") {
        list.add(Expanded(
            child: WidgetFactory.create(widgetModel.modName,
                isSliver: false, model: item)[0]));
        continue;
      }
      list.addAll(WidgetFactory.create(widgetModel.modName,
          isSliver: false, model: item));
    }
  }
  return list;
}
