import 'package:flutter/material.dart';
import 'package:liftmanager/res/gaps.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/utils/toast.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/internal/search/search_router.dart';
import 'package:liftmanager/widgets/app_search_bar.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/internal/bbs/bbs_router.dart';
import 'package:liftmanager/widgets/bbs_content.dart';

import 'package:liftmanager/mvp/base_page_state.dart';
import 'package:liftmanager/internal/wode/presenter/error_list_presenter.dart';
import 'package:liftmanager/internal/wode/model/punishments_model.dart';
import 'package:liftmanager/utils/time_format.dart';
import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
import 'package:liftmanager/widgets/state_layout.dart';
import 'package:provider/provider.dart';
import 'package:liftmanager/widgets/my_refresh_list.dart';
import 'package:liftmanager/utils/url.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:liftmanager/internal/wode/wode_router.dart';

class ProductList extends StatefulWidget {
  // QuestionList(this.index);

  // final String index;

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

class ProductListState
    extends BasePageState<ProductList, ProductListPresenter> {
  BaseListProvider<Records> provider = BaseListProvider<Records>();
  ScrollController _scrollController = new ScrollController();
  int _page = 1;
  String searchWord;
  @override
  void initState() {
    provider.setStateTypeNotNotify(StateType.loading);
    super.initState();
    _onRefresh();
    print(66666);
  }

  @override
  void dispose() {
    _scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;

    return ChangeNotifierProvider<BaseListProvider<Records>>(
        create: (_) => provider,
        child: Scaffold(
            appBar: MyAppBar(
              centerTitle: "违规记录",
              // backgroundColor:Colors.transparent,
            ),
            body: Container(
                child: Column(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: Consumer<BaseListProvider<Records>>(
                        builder: (_, provider, __) {
                      return MyListView(
                        key: Key('expertsPunishments_list'),
                        itemCount: provider.list.length,
                        stateType: provider.stateType,
                        onRefresh: _onRefresh,
                        pageSize: 10,
                        loadMore: _loadMore,
                        hasMore: provider.hasMore,
                        itemBuilder: (_, index) {
                          return InkWell(
                            child: Container(
                              padding: EdgeInsets.only(
                                  left: ScreenUtil().setWidth(15),
                                  right: ScreenUtil().setWidth(15),
                                  top: ScreenUtil().setHeight(10),
                                  bottom: ScreenUtil().setHeight(10)),
                              decoration: BoxDecoration(
                                border: Border(
                                  bottom: BorderSide(
                                      width: 0.5, color: Colours.line),
                                ),
                              ),
                              child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    ClipRRect(
                                      borderRadius: BorderRadius.circular(5),
                                      child: Container(
                                        padding: EdgeInsets.only(
                                            right: ScreenUtil().setWidth(10)),
                                        child: LoadNetworkImage(
                                              provider.list[index].picUrl,
                                          // fit: BoxFit.cover,
                                          width: ScreenUtil().setWidth(90),
                                          height: ScreenUtil().setWidth(90),
                                        ),
                                      ),
                                    ),
                                    Column(
                                      crossAxisAlignment:CrossAxisAlignment.start,
                                      mainAxisAlignment: MainAxisAlignment.start,
                                      children: <Widget>[
                                        Container(
                                          padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(10)),
                                          child:Text(
                                          provider.list[index].title??"",
                                          textAlign: TextAlign.left,
                                          style: TextStyle(
                                            fontSize: ScreenUtil().setSp(16),
                                            color: Color(0xff333333),
                                          ),
                                        ),
                                        ),
                                        
                                        Column(
                                          mainAxisAlignment: MainAxisAlignment.start,
                                          crossAxisAlignment:CrossAxisAlignment.start,
                                          children: <Widget>[
                                            Container(
                                              width: width*0.65,
                                              child: Text(
                                                provider.list[index].des??"",
                                                textAlign: TextAlign.left,
                                                style: TextStyle(
                                                  fontSize: ScreenUtil().setSp(14),
                                                  color: Color(0xff999999),
                                                ),
                                                maxLines: 2,
                                                overflow: TextOverflow.ellipsis,
                                              ),
                                            ),
                                            SizedBox(
                                              height: 10,
                                            ),
                                            Text(
                                              "￥${provider.list[index].punishAmount??""}",
                                              textAlign: TextAlign.left,
                                              style: TextStyle(
                                                fontSize: ScreenUtil().setSp(16),
                                                color: Color(0xffff0000),
                                              ),
                                            ),
                                          ],
                                        )
                                      ],
                                    ),
                                  ]),
                            ),
                            onTap: () {
                              print(index);
                              NavigatorUtils.push(context,
                                  "${WodeRouter.errorRecordDetail}?id=${provider.list[index].id.toString()}");
                            },
                          );
                        },
                      );
                    }))
              ],
            ))));
  }

  Future _onRefresh() async {
    _page = 1;
    await presenter.getShopList(_page);
  }

  Future _loadMore() async {
    _page++;
    await presenter.getShopList(_page);
  }

  @override
  ProductListPresenter createPresenter() {
    return ProductListPresenter();
  }
}
