import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hyzp_ybqx/components/commonFun.dart';
import 'package:hyzp_ybqx/pages/Works/TJXX/tj_data.dart';
import 'package:hyzp_ybqx/pages/Works/TJXX/today_list_zpjl_content_new.dart';
import 'package:hyzp_ybqx/services/EventBus.dart';

import '../../../components/commonFun.dart';
import '../../../components/doJSON.dart';
import '../../../components/hyxx_data_handle.dart';
import '../../../services/EventBus.dart';

//TodayList是本项目中“今日记录列表”的统一缩写，包括：今日抓拍、今日初审、今日复审、今日推送
class TodayList extends StatefulWidget {
  //todayListLx为今日记录列表类型，'jrzp'今日抓拍、'hycs'今日初审、'hyfh'今日复审、'tsjj'今日推送
  TodayList({this.todayListLx, this.title, Key key}) : super(key: key);
  String todayListLx;
  String title = '';

  _TodayListPageState createState() => _TodayListPageState();
}

class _TodayListPageState extends State<TodayList> {
  //try_setState();   //避免如下异常报错
  try_setState() {
    try {
      setState(() {});
    } catch (e) {
      print('setState(() {})异常：${e}');
    }
  }

  @override
  void dispose() {
    _controller.dispose(); //销毁控制器
    super.dispose();
  }

  // List listTodayList = [];
  Map<String, Map> mapTodayListLx = {
    'jrzp': {
      'text': '今日抓拍记录',
      'text0': '今日抓拍',
      'data': mapStatisInfo['今日抓拍'],
    },
    'hycs': {
      'text': '今日初审记录',
      'text0': '今日初审',
      'data': mapStatisInfo['今日初审'],
    },
    'hyfh': {
      'text': '今日复审记录',
      'text0': '今日复审',
      'data': mapStatisInfo['今日复审'],
    },
    'tsjj': {
      'text': '今日推送记录',
      'text0': '今日推送',
      'data': mapStatisInfo['今日推送'],
    },
  };

  /*
    map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
    map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
    map['dwip'] = listDwinfoGetList2[i]['dwip'];

  listAllStatisData =
  [
        {
            "id": 1,
            "dwip": "172.16.3.1",
            "dwmc": "锦绣花园",
            "zp_all": 54,
            "hyc_all": 52,
            "zp_today": 1,
            "sends": 0,
            "send_all": 33,
            "csnum": 1,
            "fsnum": 0,
            "cll_today": 6420,
            "cll_all": 3225733
        },
        ...
  ];
  */

  @override
  void initState() {
    //todayListLx为今日记录列表类型，'jrzp'今日抓拍、'hycs'今日初审、'hyfh'今日复审、'tsjj'今日推送
    switch (widget.todayListLx) {
      case 'jrzp':
        listTodayList = listTodayZpjl;
        mapTodayListDataText['车牌颜色'] = 'cpys';
        break;
      case 'hycs':
        listTodayList = listTodayChjl;
        break;
      case 'hyfh':
        listTodayList = listTodayFhjl;
        break;
      case 'tsjj':
        listTodayList = listTodayTsjl;
        break;
      default:
        break;
    }

    if (listTodayList.isEmpty) {
      _empty = '\n' + mapTodayListLx[widget.todayListLx]['text'] + _emptyInfo;
    }

    //按照用户选择的_selectedValue、_descending对listHycsGetList2进行排序，并延时更新
    _listSort();
    firstIndex = 0;
    lastIndex = 7;

    //监听违章信息数据审核事件
    eventBus.on<WzxxDataAuditEvent>().listen((event) async {
      print('HycsGetList: ' + event.str);
      //按照用户选择的_selectedValue、_descending对listHycsGetList2进行排序，并延时更新
      if (listTodayList.isEmpty) {
        _empty = _emptyInfo;
        try_setState();
        return;
      }
      _listSort();
    });

    //监听违章信息Listview滚动事件
    eventBus.on<WzxxDataScrollEvent>().listen((event) async {
      firstIndex = event.firstIndex;
      lastIndex = event.lastIndex;
      try_setState();
    });

    super.initState();
  }

  // 车牌号码
  // 车牌颜色
  // 车辆类型
  // 林格曼黑度
  // 抓拍次数
  // 首次抓拍时间
  // 首次抓拍地点
  int today = 0;
  int sum = 0;
  String _emptyInfo = '为空';
  String _empty = '';

  //List<String> itemList = [
  //   '林格曼黑度',
  //   '抓拍时间',
  //   '抓拍地点',
  //   '车牌颜色',
  //   '车辆类型',
  // ];
  //
  // //todayListLx为今日记录列表类型，'jrzp'今日抓拍、'hycs'今日初审、'hyfh'今日复审、'tsjj'今日推送
  // //添加按'推送状态'排序
  // if (widget.todayListLx == 'hycs' ||
  //     widget.todayListLx == 'hyfh' ||
  //     widget.todayListLx == 'tsjj') {
  //   itemList.add('抓拍次数');
  // }
  // if (widget.todayListLx == 'hyfh' || widget.todayListLx == 'tsjj') {
  //   itemList.add('推送状态');
  // }

  Map<String, String> mapTodayListDataText = {
    "林格曼黑度": "lgmzs",
    "抓拍时间": "zpsj",
    "抓拍地点": "dwip",
    "车牌颜色": "plate_color",
    "车辆类型": "cplx",
    "推送状态": "tszt",
  };

  //已加上tszt 推送状态字段，0->未推送，1->推送失败，2->推送成功，3->不推送（规定时间段内已有处罚记录的）
  Map mpaTszt = {
    0: '未推送',
    1: '推送失败',
    2: '推送成功',
    3: '不推送（规定时间段内已有处罚记录）',
  };

  //App.Car_Statis.GetStaYjxx，获取抓拍统计数据
  //{
  //     "ret": 200,
  //     "data": {
  //         "today": {
  //             "total": 8,
  //             "data": [
  //                 {
  //                     "id": 428560,
  //                     "car_number": "川Q31796",
  //                     "cpys": "黄色",
  //                     "zpsj": "2021-04-05 09:30:14",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/553778bd21d80dfb073aec3b0d436140.jpg",
  //                     "video_url": "video/2_6063_20210405_093014_川Q31796.mp4"
  //                 },
  //                 {
  //                     "id": 428561,
  //                     "car_number": "川QL9963",
  //                     "cpys": "蓝色",
  //                     "zpsj": "2021-04-05 10:35:06",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/4c5ddfe98daee099721a398d9eb35ba1.jpg",
  //                     "video_url": "video/2_6063_20210405_103506_川Q37902.mp4"
  //                 },
  //                 {
  //                     "id": 428562,
  //                     "car_number": "川QL9963",
  //                     "cpys": "蓝色",
  //                     "zpsj": "2021-04-05 10:35:06",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/8b9c1a4b494dc8e41346874380d9a80d.jpg",
  //                     "video_url": "video/2_6063_20210405_103506_川QL9963.mp4"
  //                 },
  //                 {
  //                     "id": 428566,
  //                     "car_number": "川QB6360",
  //                     "cpys": "蓝色",
  //                     "zpsj": "2021-04-05 11:40:36",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/e8ff7137d8a066d956e2cdf1999a976f.jpg",
  //                     "video_url": "video/2_6063_20210405_114036_川QB6360.mp4"
  //                 },
  //                 {
  //                     "id": 428567,
  //                     "car_number": "川QL9963",
  //                     "cpys": "蓝色",
  //                     "zpsj": "2021-04-05 11:48:54",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/91b718a110f55d26c08980597cb45c2b.jpg",
  //                     "video_url": "video/2_6063_20210405_114854_川QL9963.mp4"
  //                 },
  //                 {
  //                     "id": 428570,
  //                     "car_number": "川QET268",
  //                     "cpys": "蓝色",
  //                     "zpsj": "2021-04-05 12:38:29",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/9802f31038f8704efa2d0026c9716ba4.jpg",
  //                     "video_url": "video/2_6063_20210405_123829_川QET268.mp4"
  //                 },
  //                 {
  //                     "id": 428575,
  //                     "car_number": "川Q8N899",
  //                     "cpys": "蓝色",
  //                     "zpsj": "2021-04-05 13:18:08",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/784d03dd6e392d6ba067b1d168fd3a95.jpg",
  //                     "video_url": "video/2_6063_20210405_131808_川Q8N899.mp4"
  //                 },
  //                 {
  //                     "id": 428577,
  //                     "car_number": "川QL9963",
  //                     "cpys": "蓝色",
  //                     "zpsj": "2021-04-05 13:31:19",
  //                     "dwip": "172.16.3.2",
  //                     "dwms": "宜飞路石马溪大桥附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/b4bbf23ade7e1cb403446afafbb84bde.jpg",
  //                     "video_url": "video/2_6063_20210405_133119_川QL9963.mp4"
  //                 }
  //             ]
  //         },
  //         "all": 91
  //     },
  //     "msg": ""
  // }

  //App.Car_Statis.GetStaHyc，获取已审核黑烟车统计数据
  //{
  //     "ret": 200,
  //     "data": {
  //         "total": 88,
  //         "sends": {
  //             "total": 3,
  //             "data": [
  //                 {
  //                     "id": 4545,
  //                     "plate_id": "川15A2539",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 12:33:20",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:40:47",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "fs_username": "肖曦",
  //                     "fs_time": "2021-04-04 12:40:54",
  //                     "fs_tile": "黑烟车",
  //                     "fs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/49a44411b3ab6856bf2c80a9690a662b.jpg",
  //                     "video_url": "video/3_6063_20210404_123320_川15A2539.mp4",
  //                     "ts_time": 1617514823,
  //                     "tszt": 2
  //                 },
  //                 {
  //                     "id": 4546,
  //                     "plate_id": "川15A3661",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 12:45:14",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:57:38",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "fs_username": "肖曦",
  //                     "fs_time": "2021-04-04 12:57:45",
  //                     "fs_tile": "黑烟车",
  //                     "fs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/28821cb7e55ca451ebebd6c303454873.jpg",
  //                     "video_url": "video/3_6063_20210404_124514_川15A3661.mp4",
  //                     "ts_time": 1617515902,
  //                     "tszt": 2
  //                 },
  //                 {
  //                     "id": 4547,
  //                     "plate_id": "川F3B6P5",
  //                     "plate_color": "蓝色",
  //                     "zpsj": "2021-04-04 13:04:56",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 13:11:21",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "fs_username": "肖曦",
  //                     "fs_time": "2021-04-04 13:11:58",
  //                     "fs_tile": "黑烟车",
  //                     "fs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/9510551a8eb22d176917e57f99d59cff.jpg",
  //                     "video_url": "video/3_6063_20210404_130456_川F3B6P5.mp4",
  //                     "ts_time": 1617516742,
  //                     "tszt": 2
  //                 }
  //             ]
  //         },
  //         "csnum": {
  //             "total": 4,
  //             "data": [
  //                 {
  //                     "id": 4544,
  //                     "plate_id": "川15A2563",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 11:31:11",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:05:16",
  //                     "cs_tile": "非黑烟车",
  //                     "cs_shuoming": "误报，或肉眼无法识别",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/e936524e92f90541cbaeca3b092c95be.jpg",
  //                     "video_url": "video/3_6063_20210404_113111_川15A2563.mp4",
  //                     "tszt": 0
  //                 },
  //                 {
  //                     "id": 4545,
  //                     "plate_id": "川15A2539",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 12:33:20",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:40:47",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/49a44411b3ab6856bf2c80a9690a662b.jpg",
  //                     "video_url": "video/3_6063_20210404_123320_川15A2539.mp4",
  //                     "tszt": 2
  //                 },
  //                 {
  //                     "id": 4546,
  //                     "plate_id": "川15A3661",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 12:45:14",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:57:38",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/28821cb7e55ca451ebebd6c303454873.jpg",
  //                     "video_url": "video/3_6063_20210404_124514_川15A3661.mp4",
  //                     "tszt": 2
  //                 },
  //                 {
  //                     "id": 4547,
  //                     "plate_id": "川F3B6P5",
  //                     "plate_color": "蓝色",
  //                     "zpsj": "2021-04-04 13:04:56",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 13:11:21",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/9510551a8eb22d176917e57f99d59cff.jpg",
  //                     "video_url": "video/3_6063_20210404_130456_川F3B6P5.mp4",
  //                     "tszt": 2
  //                 }
  //             ]
  //         },
  //         "fsnum": {
  //             "total": 4,
  //             "data": [
  //                 {
  //                     "id": 4544,
  //                     "plate_id": "川15A2563",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 11:31:11",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:05:16",
  //                     "cs_tile": "非黑烟车",
  //                     "cs_shuoming": "误报，或肉眼无法识别",
  //                     "fs_username": "肖曦",
  //                     "fs_time": "2021-04-04 12:05:54",
  //                     "fs_tile": "非黑烟车",
  //                     "fs_shuoming": "误报，或肉眼无法识别",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/e936524e92f90541cbaeca3b092c95be.jpg",
  //                     "video_url": "video/3_6063_20210404_113111_川15A2563.mp4",
  //                     "tszt": 0
  //                 },
  //                 {
  //                     "id": 4545,
  //                     "plate_id": "川15A2539",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 12:33:20",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:40:47",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "fs_username": "肖曦",
  //                     "fs_time": "2021-04-04 12:40:54",
  //                     "fs_tile": "黑烟车",
  //                     "fs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/49a44411b3ab6856bf2c80a9690a662b.jpg",
  //                     "video_url": "video/3_6063_20210404_123320_川15A2539.mp4",
  //                     "tszt": 2
  //                 },
  //                 {
  //                     "id": 4546,
  //                     "plate_id": "川15A3661",
  //                     "plate_color": "绿色",
  //                     "zpsj": "2021-04-04 12:45:14",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "农用车",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 12:57:38",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "fs_username": "肖曦",
  //                     "fs_time": "2021-04-04 12:57:45",
  //                     "fs_tile": "黑烟车",
  //                     "fs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/28821cb7e55ca451ebebd6c303454873.jpg",
  //                     "video_url": "video/3_6063_20210404_124514_川15A3661.mp4",
  //                     "tszt": 2
  //                 },
  //                 {
  //                     "id": 4547,
  //                     "plate_id": "川F3B6P5",
  //                     "plate_color": "蓝色",
  //                     "zpsj": "2021-04-04 13:04:56",
  //                     "dwip": "172.16.3.3",
  //                     "dwms": "岷江南路森林小区附近",
  //                     "cplx": "其它",
  //                     "lgmzs": 3,
  //                     "cs_username": "肖曦",
  //                     "cs_time": "2021-04-04 13:11:21",
  //                     "cs_tile": "黑烟车",
  //                     "cs_shuoming": "黑烟超标，交由交警处罚",
  //                     "fs_username": "肖曦",
  //                     "fs_time": "2021-04-04 13:11:58",
  //                     "fs_tile": "黑烟车",
  //                     "fs_shuoming": "黑烟超标，交由交警处罚",
  //                     "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/9510551a8eb22d176917e57f99d59cff.jpg",
  //                     "video_url": "video/3_6063_20210404_130456_川F3B6P5.mp4",
  //                     "tszt": 2
  //                 }
  //             ]
  //         }
  //     },
  //     "msg": ""
  // }

  String wipeYear(String date) {
    date = date.trim();
    return date.substring(date.indexOf('-') + 1);
  }

  Map mapColor = {'黑烟车': Colors.red, '非黑烟车': Colors.green};

  Widget _getListTile(BuildContext context, indexRecord) {
    double _width = 160;
    //todayListLx为今日记录列表类型，'jrzp'今日抓拍、'hycs'今日初审、'hyfh'今日复审、'tsjj'今日推送
    switch (widget.todayListLx) {
      case 'jrzp':
        return Column(
          children: <Widget>[
            ListTile(
              //"today": {
              //    "total": 8,
              //    "data": [
              //        {
              //            "id": 428560,
              //            "car_number": "川Q31796",
              //            "cpys": "黄色",
              //            "zpsj": "2021-04-05 09:30:14",
              //            "dwip": "172.16.3.2",
              //            "dwms": "宜飞路石马溪大桥附近",
              //            "cplx": "其它",
              //            "lgmzs": 3,
              //            "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/553778bd21d80dfb073aec3b0d436140.jpg",
              //            "video_url": "video/2_6063_20210405_093014_川Q31796.mp4"
              //        },

              /*
                map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
                map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
                map['dwip'] = listDwinfoGetList2[i]['dwip'];

              listAllStatisData =
              [
                    {
                        "id": 1,
                        "dwip": "172.16.3.1",
                        "dwmc": "锦绣花园",
                        "zp_all": 54,
                        "hyc_all": 52,
                        "zp_today": 1,
                        "sends": 0,
                        "send_all": 33,
                        "csnum": 1,
                        "fsnum": 0,
                        "cll_today": 6420,
                        "cll_all": 3225733
                    },
                    ...
              ];
              */
              contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
              enabled: true,
              title: Text(
                  "${(indexRecord + 1).toString()}. ${listTodayList[indexRecord]['car_number']}" +
                      '(${listTodayList[indexRecord]['cpys']})，${listTodayList[indexRecord]['cplx']}，' +
                      '黑度 ${listTodayList[indexRecord]['lgmzs'].toString()}',
                  style: TextStyle(fontSize: 14)),
              subtitle: Text(getDate(listTodayList[indexRecord]['zpsj']),
                  style: TextStyle(
                      fontSize: 14,
                      color: isToday(listTodayList[indexRecord]['zpsj'])
                          ? Colors.lightBlue
                          : Colors.black,
                      fontWeight: FontWeight.bold)),
              trailing: Container(
                width: _width - 10,
                child: Text(
                  getDwmc(listTodayList[indexRecord]['dwip']) +
                      '，${listTodayList[indexRecord]['dwms']}',
                  maxLines: 3,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(fontSize: 14),
                ),
              ),
              onTap: () async {
                int ret = -1;
                if (widget.todayListLx == 'jrzp') {
                  ret = await Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => TodayListZpjlContentNew(
                          hyshlx: widget.todayListLx,
                          text: mapTodayListLx[widget.todayListLx]['text0'],
                          index: indexRecord),
                      // num: '（${indexRecord + 1}/${listTodayList.length}）',
                      // mapZpjl: listTodayList[indexRecord]),
                    ),
                  );
                }

                // int ret = -1;
                // if (widget.todayListLx == 'fhycx') {
                //   ret = await Navigator.of(context).push(
                //     MaterialPageRoute(
                //       builder: (context) => FhycxContentNew(
                //           hyshlx: widget.todayListLx,
                //           title: '非黑烟车',
                //           indexRecord: indexRecord,
                //           id: listTodayList[indexRecord]['id']),
                //     ),
                //   );
                //   print('hyshContentFirstAudit整型返回值：-1 表示出现异常，其余为更新结果，1表示成功，0表示无更新，false表示失败');
                // } else if (widget.todayListLx == 'tsjj') {
                //   ret = await Navigator.of(context).push(
                //     MaterialPageRoute(
                //       builder: (context) => TsjjContentNew(
                //           hyshlx: widget.todayListLx,
                //           title: '推送交警详情',
                //           indexRecord: indexRecord,
                //           id: listTodayList[indexRecord]['id']),
                //     ),
                //   );
                //   print('hyshContentFirstAudit整型返回值：-1 表示出现异常，其余为更新结果，1表示成功，0表示无更新，false表示失败');
                // } else {
                //   ret = await Navigator.of(context).push(
                //     MaterialPageRoute(
                //       builder: (context) => HyshContentNew(
                //           hyshlx: widget.todayListLx,
                //           title: '违章审核详情',
                //           indexRecord: indexRecord,
                //           id: listTodayList[indexRecord]['id']),
                //     ),
                //   );
                //   print('hyshContentFirstAudit整型返回值：-1 表示出现异常，其余为更新结果，1表示成功，0表示无更新，false表示失败');
                // }
                // print('ret = $ret');
              },
            ),
            Divider(
              height: 1.0,
            ),
          ],
        );
        break;
      case 'hycs':
        return Column(
          children: <Widget>[
            ListTile(
              //"csnum": {
              //    "total": 4,
              //    "data": [
              //        {
              //            "id": 4544,
              //            "plate_id": "川15A2563",
              //            "plate_color": "绿色",
              //            "zpsj": "2021-04-04 11:31:11",
              //            "dwip": "172.16.3.3",
              //            "dwms": "岷江南路森林小区附近",
              //            "cplx": "农用车",
              //            "lgmzs": 3,
              //            "cs_username": "肖曦",
              //            "cs_time": "2021-04-04 12:05:16",
              //            "cs_tile": "非黑烟车",
              //            "cs_shuoming": "误报，或肉眼无法识别",
              //            "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/e936524e92f90541cbaeca3b092c95be.jpg",
              //            "video_url": "video/3_6063_20210404_113111_川15A2563.mp4",
              //            "tszt": 0
              //        },
              contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
              enabled: true,
              onTap: () async {
                int ret = -1;
                if (widget.todayListLx == 'hycs') {
                  ret = await Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => TodayListZpjlContentNew(
                          hyshlx: widget.todayListLx,
                          text: mapTodayListLx[widget.todayListLx]['text0'],
                          index: indexRecord),
                      // num: '（${indexRecord + 1}/${listTodayList.length}）',
                      // mapZpjl: listTodayList[indexRecord]),
                    ),
                  );
                }
              },
              title: RichText(
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
                text: TextSpan(
                    text:
                        "${(indexRecord + 1).toString()}. ${listTodayList[indexRecord]['plate_id']}" +
                            '(${listTodayList[indexRecord]['plate_color']})，',
                    style: TextStyle(fontSize: 14, color: Colors.black),
                    children: [
                      TextSpan(
                          text: '${listTodayList[indexRecord]['cplx']}，' +
                              getDwmc(listTodayList[indexRecord]['dwip']) +
                              '，黑度 ${listTodayList[indexRecord]['lgmzs']}',
                          style: TextStyle(fontSize: 12, color: Colors.black)),
                    ]),
              ),
              subtitle: RichText(
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
                text: TextSpan(
                    text: getDate(listTodayList[indexRecord]['zpsj']),
                    style: TextStyle(
                        fontSize: 14,
                        color: isToday(listTodayList[indexRecord]['zpsj'])
                            ? Colors.lightBlue
                            : Colors.black,
                        fontWeight: FontWeight.bold),
                    children: [
                      // TextSpan(
                      //     text: '，黑度 ${listTodayList[indexRecord]['lgmzs'].toString()}',
                      //     style: DefaultTextStyle.of(context).style),
                    ]),
              ),
              trailing: Container(
                width: _width - 20,
                child: RichText(
                  overflow: TextOverflow.ellipsis,
                  maxLines: 3,
                  text: TextSpan(
                      style: TextStyle(
                          fontSize: 14,
                          color: mapColor[listTodayList[indexRecord]['cs_tile'].trim()]),
                      text: '初审:${listTodayList[indexRecord]['cs_tile']}',
                      children: [
                        TextSpan(
                            text: '，${listTodayList[indexRecord]['cs_username']}，',
                            style: TextStyle(fontSize: 14, color: Colors.black)),
                        TextSpan(
                            text: '${listTodayList[indexRecord]['cs_time']}',
                            style: TextStyle(fontSize: 14, color: Colors.black)),
                        // TextSpan(
                        //     text: '，黑度 ${listTodayList[indexRecord]['lgmzs'].toString()}',
                        //     style: DefaultTextStyle.of(context).style),
                      ]),
                ),
              ),
            ),
            Divider(
              height: 1.0,
            ),
          ],
        );
        break;
      case 'hyfh':
        return Column(
          children: <Widget>[
            ListTile(
              //"fsnum": {
              //    "total": 4,
              //    "data": [
              //        {
              //            "id": 4544,
              //            "plate_id": "川15A2563",
              //            "plate_color": "绿色",
              //            "zpsj": "2021-04-04 11:31:11",
              //            "dwip": "172.16.3.3",
              //            "dwms": "岷江南路森林小区附近",
              //            "cplx": "农用车",
              //            "lgmzs": 3,
              //            "cs_username": "肖曦",
              //            "cs_time": "2021-04-04 12:05:16",
              //            "cs_tile": "非黑烟车",
              //            "cs_shuoming": "误报，或肉眼无法识别",
              //            "fs_username": "肖曦",
              //            "fs_time": "2021-04-04 12:05:54",
              //            "fs_tile": "非黑烟车",
              //            "fs_shuoming": "误报，或肉眼无法识别",
              //            "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/e936524e92f90541cbaeca3b092c95be.jpg",
              //            "video_url": "video/3_6063_20210404_113111_川15A2563.mp4",
              //            "tszt": 0
              //        },

              //已加上tszt 推送状态字段，0->未推送，1->推送失败，2->推送成功，3->不推送（规定时间段内已有处罚记录的）
              contentPadding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 0),
              enabled: true,
              onTap: () async {
                int ret = -1;
                if (widget.todayListLx == 'hyfh') {
                  ret = await Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => TodayListZpjlContentNew(
                          hyshlx: widget.todayListLx,
                          text: mapTodayListLx[widget.todayListLx]['text0'],
                          index: indexRecord),
                      // num: '（${indexRecord + 1}/${listTodayList.length}）',
                      // mapZpjl: listTodayList[indexRecord]),
                    ),
                  );
                }
              },
              title: RichText(
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
                text: TextSpan(
                    text:
                        "${(indexRecord + 1).toString()}. ${listTodayList[indexRecord]['plate_id']}" +
                            '(${listTodayList[indexRecord]['plate_color']})，',
                    style: TextStyle(fontSize: 14, color: Colors.black),
                    children: [
                      TextSpan(
                          text: '${listTodayList[indexRecord]['cplx']}，' +
                              getDwmc(listTodayList[indexRecord]['dwip']) +
                              '，黑度 ${listTodayList[indexRecord]['lgmzs']}',
                          style: TextStyle(fontSize: 12, color: Colors.black)),
                    ]),
              ),
              subtitle: RichText(
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
                text: TextSpan(
                    text: getDate(listTodayList[indexRecord]['zpsj']),
                    style: TextStyle(
                        fontSize: 14,
                        color: isToday(listTodayList[indexRecord]['zpsj'])
                            ? Colors.lightBlue
                            : Colors.black,
                        fontWeight: FontWeight.bold),
                    children: [
                      // TextSpan(
                      //     text: '，黑度 ${listTodayList[indexRecord]['lgmzs'].toString()}',
                      //     style: DefaultTextStyle.of(context).style),
                    ]),
              ),
              trailing: Container(
                width: _width + 5,
                child: RichText(
                  overflow: TextOverflow.ellipsis,
                  maxLines: 3,
                  text: TextSpan(
                      style: TextStyle(
                          fontSize: 13,
                          color: mapColor[listTodayList[indexRecord]['cs_tile'].trim()]),
                      text: '初审:${listTodayList[indexRecord]['cs_tile']}',
                      children: [
                        TextSpan(
                            text: '，${listTodayList[indexRecord]['cs_username']}，',
                            style: TextStyle(fontSize: 13, color: Colors.black)),
                        TextSpan(
                            text: '${wipeYear(listTodayList[indexRecord]['cs_time'])}；',
                            style: TextStyle(fontSize: 11, color: Colors.black)),
                        TextSpan(
                            text: '复审:${listTodayList[indexRecord]['fs_tile']}',
                            style: TextStyle(
                                fontSize: 13,
                                color: mapColor[listTodayList[indexRecord]['fs_tile'].trim()])),
                        TextSpan(
                            text: '，${listTodayList[indexRecord]['fs_username']}，',
                            style: TextStyle(fontSize: 13, color: Colors.black)),
                        TextSpan(
                            text: '${wipeYear(listTodayList[indexRecord]['fs_time'])}',
                            style: TextStyle(fontSize: 11, color: Colors.black)),
                        // TextSpan(
                        //     text: '，黑度 ${listTodayList[indexRecord]['lgmzs'].toString()}',
                        //     style: DefaultTextStyle.of(context).style),
                      ]),
                ),
              ),
            ),
            Divider(
              height: 1.0,
            ),
          ],
        );
        break;
      case 'tsjj':
        return Column(
          children: <Widget>[
            ListTile(
              //"sends": {
              //    "total": 3,
              //    "data": [
              //        {
              //            "id": 4545,
              //            "plate_id": "川15A2539",
              //            "plate_color": "绿色",
              //            "zpsj": "2021-04-04 12:33:20",
              //            "dwip": "172.16.3.3",
              //            "dwms": "岷江南路森林小区附近",
              //            "cplx": "农用车",
              //            "lgmzs": 3,
              //            "cs_username": "肖曦",
              //            "cs_time": "2021-04-04 12:40:47",
              //            "cs_tile": "黑烟车",
              //            "cs_shuoming": "黑烟超标，交由交警处罚",
              //            "fs_username": "肖曦",
              //            "fs_time": "2021-04-04 12:40:54",
              //            "fs_tile": "黑烟车",
              //            "fs_shuoming": "黑烟超标，交由交警处罚",
              //            "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/49a44411b3ab6856bf2c80a9690a662b.jpg",
              //            "video_url": "video/3_6063_20210404_123320_川15A2539.mp4",
              //            "ts_time": 1617514823,
              //            "tszt": 2
              //        },
              contentPadding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 0),
              enabled: true,
              onTap: () async {
                int ret = -1;
                if (widget.todayListLx == 'tsjj') {
                  ret = await Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => TodayListZpjlContentNew(
                        hyshlx: widget.todayListLx,
                        text: mapTodayListLx[widget.todayListLx]['text0'],
                        index: indexRecord,
                        // num: '（${indexRecord + 1}/${listTodayList.length}）',
                        // mapZpjl: listTodayList[indexRecord],
                        tsztText: mapTsztText[getInt(listTodayList[indexRecord]['tszt'])],
                      ),
                    ),
                  );
                }
              },
              title: RichText(
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
                text: TextSpan(
                    text:
                        "${(indexRecord + 1).toString()}. ${listTodayList[indexRecord]['plate_id']}" +
                            '(${listTodayList[indexRecord]['plate_color']})，',
                    style: TextStyle(fontSize: 14, color: Colors.black),
                    children: [
                      TextSpan(
                          text: '${listTodayList[indexRecord]['cplx']}，' +
                              getDwmc(listTodayList[indexRecord]['dwip']) +
                              '，黑度 ${listTodayList[indexRecord]['lgmzs']}',
                          style: TextStyle(fontSize: 12, color: Colors.black)),
                    ]),
              ),
              subtitle: RichText(
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
                text: TextSpan(
                    text: getDate(listTodayList[indexRecord]['zpsj']),
                    style: TextStyle(
                        fontSize: 14,
                        color: isToday(listTodayList[indexRecord]['zpsj'])
                            ? Colors.lightBlue
                            : Colors.black,
                        fontWeight: FontWeight.bold),
                    children: [
                      // TextSpan(
                      //     text: '，黑度 ${listTodayList[indexRecord]['lgmzs'].toString()}',
                      //     style: DefaultTextStyle.of(context).style),
                    ]),
              ),
              trailing: Container(
                width: _width + 5,
                child: RichText(
                  overflow: TextOverflow.ellipsis,
                  maxLines: 3,
                  text: TextSpan(
                      style: TextStyle(
                          fontSize: 13,
                          color: mapColor[listTodayList[indexRecord]['cs_tile'].trim()]),
                      text: '初审:${listTodayList[indexRecord]['cs_tile']}',
                      children: [
                        TextSpan(
                            text: '，${listTodayList[indexRecord]['cs_username']}，',
                            style: TextStyle(fontSize: 13, color: Colors.black)),
                        TextSpan(
                            text: '${wipeYear(listTodayList[indexRecord]['cs_time'])}；',
                            style: TextStyle(fontSize: 10, color: Colors.black)),
                        TextSpan(
                            text: '复审:${listTodayList[indexRecord]['fs_tile']}',
                            style: TextStyle(
                                fontSize: 13,
                                color: mapColor[listTodayList[indexRecord]['fs_tile'].trim()])),
                        TextSpan(
                            text: '，${listTodayList[indexRecord]['fs_username']}，',
                            style: TextStyle(fontSize: 13, color: Colors.black)),
                        TextSpan(
                            text: '${wipeYear(listTodayList[indexRecord]['fs_time'])}',
                            style: TextStyle(fontSize: 10, color: Colors.black)),
                        TextSpan(
                            text: '，${mapTsztText[getInt(listTodayList[indexRecord]['tszt'])]}',
                            style: TextStyle(fontSize: 11, color: Colors.blueAccent)),
                        // TextSpan(
                        //     text: '，黑度 ${listTodayList[indexRecord]['lgmzs'].toString()}',
                        //     style: DefaultTextStyle.of(context).style),
                      ]),
                ),
              ),
            ),
            Divider(
              height: 1.0,
            ),
          ],
        );
        break;
      default:
        break;
    }
  }

  int getInt(var num) {
    if (num is int) {
      return num;
    } else if (num is String) {
      return int.parse(num);
    } else {
      return -1;
    }
  }

  ScrollController _controller = ScrollController(); //ListView控制器
  bool isLoading = false; //正在处理下载数据、跳转到首项、跳转到尾项等操作
  int firstIndex = 0; //ListView当前显示页面首项0基序号
  int lastIndex = 0; //ListView当前显示页面末项0基序号
  int itemOnPage = 8; //估计一屏显示的项目数量

  Widget getIconButton({IconData iconData, var onPressed, double iconSize = 22}) {
    return SizedBox(
      height: iconSize,
      width: iconSize + 10,
      child: IconButton(
        padding: EdgeInsets.all(0.0),
        icon: Icon(iconData, size: iconSize, color: Colors.white),
        onPressed: onPressed,
      ),
    );
  }

  //获取 listTodayList 中今日抓拍记录总数
  int getTodaySum() {
    int i = 0;
    for (Map record in listTodayList) {
      if (isToday(record['zpsj'])) {
        i++;
      }
    }
    return i;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // here the desired height
        child: AppBar(
          automaticallyImplyLeading: false,
          centerTitle: true,
          //leading: Text(''),
          titleSpacing: 0.0,
          //设置title的左边距
          flexibleSpace: Container(
            //SizedBox(height: ScreenUtil().statusBarHeight), //显示顶部状态栏
            // SizedBox(height: ScreenUtil().setHeight(10)), //显示顶部状态栏
            padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight), //留出顶部状态栏高度
            child: Container(
              //height: ScreenUtil().setHeight(173),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    Color.fromRGBO(12, 186, 156, 1),
                    Color.fromRGBO(39, 127, 235, 1),
                  ],
                ),
              ),
              // decoration: BoxDecoration(
              //   gradient: LinearGradient(colors: [
              //     Color(0xFF0018EB),
              //     Color(0xFF01C1D9),
              //   ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
              // ),
            ),
          ),
          //1、第1行组件，工具按钮
          title: Padding(
            padding: EdgeInsets.only(left: 0, right: 0),
            child: Row(
              //mainAxisAlignment: MainAxisAlignment.start,
              children: [
                //1.1、返回按钮
                getIconAndTextButton(
                  iconColor: Colors.white,
                  iconData: Icons.chevron_left_outlined,
                  onPress: () {
                    Navigator.pop(context);
                  },
                ),
                //1.2、title 显示控制
                Expanded(
                  child: RichText(
                    textAlign: TextAlign.center,
                    overflow: TextOverflow.ellipsis,
                    text: TextSpan(
                      style: TextStyle(color: Colors.white, fontSize: 20),
                      children: <InlineSpan>[
                        TextSpan(text: "${mapTodayListLx[widget.todayListLx]['text']}（"),
                        TextSpan(
                            text: "${getTodaySum()}",
                            style: TextStyle(
                                fontSize: 20,
                                color: Colors.redAccent,
                                fontWeight: FontWeight.w900)),
                        TextSpan(
                            text: (widget.todayListLx == 'jrzp')
                                ? ''
                                : "/${mapTodayListLx[widget.todayListLx]['data'].toStringAsFixed(0)}"),
                        TextSpan(text: "）"),
                      ],
                    ),
                  ),
                ),
                SizedBox(width: 5),
              ],
            ),
          ),
          //1.3、尾部工具按钮组
          actions: <Widget>[
            getIconButton(
              iconData: Icons.vertical_align_top_outlined,
              onPressed: (!isLoading && (firstIndex > 0)) //未到顶部
                  ? () async {
                      if (isLoading) {
                        return;
                      }
                      isLoading = true;
                      try_setState();

                      //必须延时执行，否则不能及时完成按钮状态更新
                      Timer(
                        Duration(milliseconds: 500),
                        () {
                          _controller.jumpTo(_controller.position.minScrollExtent);
                        },
                      );

                      Timer(
                        Duration(milliseconds: 1000),
                        () {
                          // Fluttertoast.showToast(
                          //   msg: '已经跳转到开头记录！',
                          //   toastLength: Toast.LENGTH_SHORT,
                          //   gravity: ToastGravity.CENTER,
                          // );
                          firstIndex = 0;
                          lastIndex = itemOnPage - 1; //0基序号，所以需要减1
                          isLoading = false;
                          try_setState();
                        },
                      );
                    }
                  : null,
            ),
            SizedBox(width: ScreenUtil().setWidth(32)),
            getIconButton(
              iconData: Icons.vertical_align_bottom_outlined,
              onPressed: (!isLoading && (lastIndex < listTodayList.length)) //未到尾部
                  ? () async {
                      if (isLoading) {
                        return;
                      }
                      isLoading = true;
                      try_setState();

                      //必须延时执行，否则不能及时完成按钮状态更新
                      Timer(
                        Duration(milliseconds: 500),
                        () {
                          _controller.jumpTo(_controller.position.maxScrollExtent);
                        },
                      );

                      Timer(
                        Duration(milliseconds: 1000),
                        () {
                          // Fluttertoast.showToast(
                          //   msg: '已经跳转到末尾记录！',
                          //   toastLength: Toast.LENGTH_SHORT,
                          //   gravity: ToastGravity.CENTER,
                          // );
                          //0基序号需要减1，再加上底部有一组显示信息，所以需要减2
                          firstIndex = listTodayList.length - itemOnPage - 2;
                          lastIndex = listTodayList.length;
                          isLoading = false;
                          try_setState();
                        },
                      );
                    }
                  : null,
            ),
            SizedBox(width: ScreenUtil().setWidth(32)),
          ],
        ),
      ),
      body: Column(
        children: [
          //2、第2行排序按钮
          Container(
            height: ScreenUtil().setHeight(142),
            decoration: new BoxDecoration(border: new Border.all(color: Colors.red)),
            child: Row(
              children: [
                SizedBox(width: ScreenUtil().setWidth(50)),
                Text('排序', style: TextStyle(fontSize: 18)),
                Expanded(child: SizedBox.shrink()),
                getDropdownButton(),
                SizedBox(width: ScreenUtil().setWidth(20)),
              ],
            ),
          ),
          //3、第3行组件，数据显示区域
          _empty.isNotEmpty
              ? Text(_empty, style: TextStyle(fontSize: 20))
              : (0 == listTodayList.length)
                  ? getMoreWidget(color: Colors.black38)
                  : Expanded(
                      child: ListView.custom(
                        controller: _controller,
                        cacheExtent: 1.0, // 只有设置了1.0 才能够准确的标记position 位置
                        childrenDelegate: MyChildrenDelegate(
                          _getListTile,
                          childCount: listTodayList.length,
                        ),
                      ),
                    )
        ],
      ),
    );
  }

  // Widget getDropdownButton() {
  //   return DropdownButton<String>(
  //     value: _selectedValue,
  //     onChanged: (String newValue) {
  //       setState(() {
  //         _selectedValue = newValue;
  //       });
  //     },
  //     items: <String>['One', 'Two', 'Free', 'Four'].map<DropdownMenuItem<String>>((String value) {
  //       return DropdownMenuItem<String>(
  //         value: value,
  //         child: Text(value),
  //       );
  //     }).toList(),
  //   );
  // }

  //DropdownButton需要设置初始值的时候，初始值必须是显示列表里面的值，否则会导致弹出框异常。
  // 比如说：你的DropdownButton的items属性使用的是list这个列表里面的值，那么你的初始值应该在list[index]里面取，要不就会报错。
  //
  // There should be exactly one item with [DropdownButton]'s value: 0.0.
  // Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
  // 'package:flutter/src/material/dropdown.dart':
  // Failed assertion: line 834 pos 15: 'items == null || items.isEmpty || value == null ||
  //               items.where((DropdownMenuItem<T> item) {
  //                 return item.value == value;
  //               }).length == 1'
  String _selectedValue = '抓拍时间';
  bool _descending = true;

  Widget _getImage(String _image) {
    return Container(
        margin: EdgeInsets.only(),
        height: ScreenUtil().setWidth(48),
        width: ScreenUtil().setWidth(48),
        //child: Image.asset('assets/images/ybsthbj.png', fit: BoxFit.fitHeight),
        child: Image.asset(_image,
            fit: BoxFit.cover, color: isLoading ? Theme.of(context).disabledColor : null));
  }

  // //统计今日抓拍次数 today
  // Future getToday() async {
  //   today = 0;
  //   int _yesterDayStamp = getEndDayOfYesterdayStamp();
  //   for (var item in listTodayList) {
  //     //统计今日抓拍次数
  //     if (item['zpsj'] > _yesterDayStamp) {
  //       today++;
  //     }
  //   }
  // }

  //按照用户选择的_selectedValue、_descending对listHycsGetList2进行排序，并延时更新
  Future _listSort({bool bShowToast = false}) {
    if (!isLoading && listTodayList.length > 0) {
      isLoading = true;
      try_setState();
      sum = listTodayList.length; //当前记录总数
      //getToday(); //统计今日抓拍次数 today

      switch (_selectedValue) {
        case '推送状态':
          if (_descending) {
            // Unhandled Exception: NoSuchMethodError: The method 'compareTo' was called on null.
            //按_selectedValue排序，降序
            listTodayList.sort((a, b) => (b[mapTodayListDataText[_selectedValue]])
                .compareTo(a[mapTodayListDataText[_selectedValue]]));
          } else {
            //按_selectedValue排序，升序
            listTodayList.sort((a, b) => (a[mapTodayListDataText[_selectedValue]])
                .compareTo(b[mapTodayListDataText[_selectedValue]]));
          }
          break;
        default:
          if (_descending) {
            //按_selectedValue排序，降序
            listTodayList.sort((a, b) => (b[mapTodayListDataText[_selectedValue]])
                .compareTo(a[mapTodayListDataText[_selectedValue]]));
          } else {
            //按_selectedValue排序，升序
            listTodayList.sort((a, b) => (a[mapTodayListDataText[_selectedValue]])
                .compareTo(b[mapTodayListDataText[_selectedValue]]));
          }
          break;
      }

      Future.delayed(const Duration(milliseconds: 1000), () {
        if (bShowToast) {
          Fluttertoast.showToast(
            msg: '按“${_selectedValue}”${_descending ? '降序' : '升序'}排列完成！',
            toastLength: Toast.LENGTH_SHORT,
            gravity: ToastGravity.CENTER,
          );
        }
        isLoading = false;
        try_setState(); //避免如下异常报错
      });
    }
  }

  Widget getDropdownButton() {
    //DropdownMenuItem项目文本list
    List<String> itemList = [
      '林格曼黑度',
      '抓拍时间',
      '抓拍地点',
      '车牌颜色',
      '车辆类型',
    ];

    //todayListLx为今日记录列表类型，'jrzp'今日抓拍、'hycs'今日初审、'hyfh'今日复审、'tsjj'今日推送
    //添加按'推送状态'排序
    if (widget.todayListLx == 'tsjj') {
      itemList.add('推送状态');
    }

    //获取DropdownMenuItem项目组件list
    List<DropdownMenuItem<String>> _dropDownMenuItems =
        itemList.map<DropdownMenuItem<String>>((String item) {
      return DropdownMenuItem<String>(
        value: item,
        child: getDropdownButtonItemText(item),
      );
    }).toList();

    return Padding(
      padding: EdgeInsets.only(top: 0, bottom: 0),
      child: Container(
        alignment: Alignment(0, 0),
        width: 145,
        margin: EdgeInsets.only(bottom: 0),
        padding: EdgeInsets.only(left: 0, bottom: 0),
        // decoration: BoxDecoration(
        //   border: Border.all(width: 0),
        //   //边框圆角设置
        //   borderRadius:
        //       BorderRadius.vertical(top: Radius.elliptical(2, 2), bottom: Radius.elliptical(2, 2)),
        // ),
        //DropdownButton默认有一条下划线，DropdownButtonHideUnderline去除下划线
        child: DropdownButtonHideUnderline(
          child: DropdownButton<String>(
            iconSize: ScreenUtil().setHeight(100),
            //itemHeight: ScreenUtil().setHeight(372),
            isDense: true,
            value: _selectedValue,
            items: _dropDownMenuItems,
            onChanged: (String selectedValue) {
              if (isLoading) {
                return;
              }

              if (_selectedValue == selectedValue) {
                _descending = !_descending;
              } else {
                _descending = true;
              }
              _selectedValue = selectedValue;
              print('_selectedValue = $_selectedValue');

              //按抓拍次数排序，降序
              // listHycsGetList2.sort((a, b) => (b["yjxx_id"].split(',').length.toString())
              //     .compareTo(a["yjxx_id"].split(',').length.toString()));

              //按照用户选择的_selectedValue、_descending对listHycsGetList2进行排序，并延时更新
              _listSort();
            },
          ),
        ),
      ),
    );

    //没有padding: ，会报错Failed assertion: line 1644 pos 15: 'padding != null': is
    // return Padding(
    //   // child: OutlineButton(
    //   //   borderSide: BorderSide(width: 4.0),
    //   //   child: Text('Hi'),
    //   //   onPressed: () {},
    //   //   padding: EdgeInsets.all(0),
    //   // ),
    // );

    // return SizedBox(
    //   height: 30,
    //   width: 30,
    //   child: Container(
    //     color: Colors.black45,
    //   ),
    // );

    // return Container(
    //   decoration: new BoxDecoration(
    //       border: new Border.all(color: Color(0xFFFF0000), width: 0.5),
    //       color: Color(0xFF9E9E9E),
    //       borderRadius: new BorderRadius.circular((20.0))),
    //   height: 28.0,
    //   width: 130,
    //   alignment: Alignment.center,
    //   child: Text('sdsd'),
    // );

    //   ConstrainedBox(
    //   constraints: BoxConstraints(
    //     //minWidth: double.infinity, //宽度尽可能大
    //     //minHeight: _listTileHeight, //最小高度
    //     maxHeight: 20, //最大高度
    //   ),
    // );
  }

  Widget getDropdownButtonItemText(String item) {
    return Padding(
      padding: EdgeInsets.only(bottom: ScreenUtil().setHeight(3)),
      child: Row(
        //crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            alignment: Alignment(0, 0),
            padding: EdgeInsets.only(top: ScreenUtil().setHeight(10)),
            child: item == _selectedValue
                ? _descending
                    ? _getImage('assets/images/descending.png')
                    : _getImage('assets/images/ascending.png')
                // ? Icon(Icons.arrow_downward_outlined, size: 20)
                // : Icon(Icons.arrow_upward_outlined, size: 20)
                : SizedBox(),
          ),
          SizedBox(
            width: ScreenUtil().setWidth(10),
          ),
          Container(
            //alignment: Alignment(0, -1),
            child: Text(item,
                style: TextStyle(
                    fontSize: 18,
                    color: isLoading
                        ? Theme.of(context).disabledColor
                        : item == _selectedValue
                            ? Colors.blue
                            : null)),
            // style: isLoading
            //     ? TextStyle(color: Theme.of(context).disabledColor)
            //     : (item == _selectedValue ? TextStyle(color: Colors.blue) : null)),
          ),
        ],
      ),
    );
  }

// Widget getDropdownButtonItemText(String item) {
//   return Row(
//     //crossAxisAlignment: CrossAxisAlignment.center,
//     children: [
//       Container(
//         alignment: Alignment(0, 0.28),
//         child: item == _selectedValue
//             ? _descending
//                 ? _getImage('assets/images/descending.png')
//                 : _getImage('assets/images/ascending.png')
//             // ? Icon(Icons.arrow_downward_outlined, size: 20)
//             // : Icon(Icons.arrow_upward_outlined, size: 20)
//             : SizedBox(),
//       ),
//       SizedBox(
//         width: 3,
//       ),
//       Container(
//         //alignment: Alignment(0, -1),
//         child: Text(item,
//             style: isLoading
//                 ? TextStyle(color: Theme.of(context).disabledColor)
//                 : (item == _selectedValue ? TextStyle(color: Colors.blue) : null)),
//       ),
//     ],
//   );
// }
//
// Widget getDropdownButton() {
//   //DropdownMenuItem项目文本list
//   List<String> itemList = [
//     '抓拍次数',
//     '林格曼黑度',
//     '抓拍时间',
//     '抓拍地点',
//     '车牌颜色',
//     '车牌号码',
//     '车辆类型',
//     '主键ID',
//   ];
//
//   //添加按'推送状态'排序
//   if (todayListLx != 'hycs') {
//     itemList.removeLast();
//     itemList.addAll(['推送状态', '主键ID']);
//   }
//
//   //获取DropdownMenuItem项目组件list
//   List<DropdownMenuItem<String>> _dropDownMenuItems =
//       itemList.map<DropdownMenuItem<String>>((String item) {
//     return DropdownMenuItem<String>(
//       value: item,
//       child: getDropdownButtonItemText(item),
//     );
//   }).toList();
//
//   return Padding(
//     padding: EdgeInsets.only(top: 10, bottom: 10),
//     child: Container(
//       alignment: Alignment(0.7, 0),
//       width: 125,
//       margin: EdgeInsets.only(bottom: 0),
//       padding: EdgeInsets.only(left: 0, bottom: 0),
//       decoration: BoxDecoration(
//         border: Border.all(width: 0),
//         //边框圆角设置
//         borderRadius:
//             BorderRadius.vertical(top: Radius.elliptical(2, 2), bottom: Radius.elliptical(2, 2)),
//       ),
//       //DropdownButton默认有一条下划线，DropdownButtonHideUnderline去除下划线
//       child: DropdownButtonHideUnderline(
//         child: DropdownButton<String>(
//           isDense: true,
//           value: _selectedValue,
//           items: _dropDownMenuItems,
//           onChanged: (String selectedValue) {
//             if (isLoading) {
//               return;
//             }
//
//             if (_selectedValue == selectedValue) {
//               _descending = !_descending;
//             } else {
//               _descending = true;
//             }
//             _selectedValue = selectedValue;
//             print('_selectedValue = $_selectedValue');
//
//             //按抓拍次数排序，降序
//             // listHycsGetList2.sort((a, b) => (b["yjxx_id"].split(',').length.toString())
//             //     .compareTo(a["yjxx_id"].split(',').length.toString()));
//
//             //按照用户选择的_selectedValue、_descending对listHycsGetList2进行排序，并延时更新
//             _listSort();
//           },
//         ),
//       ),
//     ),
//   );
//
//   //没有padding: ，会报错Failed assertion: line 1644 pos 15: 'padding != null': is
//   // return Padding(
//   //   // child: OutlineButton(
//   //   //   borderSide: BorderSide(width: 4.0),
//   //   //   child: Text('Hi'),
//   //   //   onPressed: () {},
//   //   //   padding: EdgeInsets.all(0),
//   //   // ),
//   // );
//
//   // return SizedBox(
//   //   height: 30,
//   //   width: 30,
//   //   child: Container(
//   //     color: Colors.black45,
//   //   ),
//   // );
//
//   // return Container(
//   //   decoration: new BoxDecoration(
//   //       border: new Border.all(color: Color(0xFFFF0000), width: 0.5),
//   //       color: Color(0xFF9E9E9E),
//   //       borderRadius: new BorderRadius.circular((20.0))),
//   //   height: 28.0,
//   //   width: 130,
//   //   alignment: Alignment.center,
//   //   child: Text('sdsd'),
//   // );
//
//   //   ConstrainedBox(
//   //   constraints: BoxConstraints(
//   //     //minWidth: double.infinity, //宽度尽可能大
//   //     //minHeight: _listTileHeight, //最小高度
//   //     maxHeight: 20, //最大高度
//   //   ),
//   // );
// }
}

//https://blog.csdn.net/u014803467/article/details/103750018
//Flutter 使用SliverChildBuilderDelegate获取ListView的第一个和最后一个可见Item序号
// 秋名山交警X 2019-12-28 23:52:52
class _SaltedValueKey extends ValueKey<Key> {
  const _SaltedValueKey(Key key)
      : assert(key != null),
        super(key);
}

class MyChildrenDelegate extends SliverChildBuilderDelegate {
  MyChildrenDelegate(
    Widget Function(BuildContext, int) builder, {
    int childCount,
    bool addAutomaticKeepAlive = true,
    bool addRepaintBoundaries = true,
  }) : super(builder,
            childCount: childCount,
            addAutomaticKeepAlives: addAutomaticKeepAlive,
            addRepaintBoundaries: addRepaintBoundaries);

  // Return a Widget for the given Exception
  Widget _createErrorWidget(dynamic exception, StackTrace stackTrace) {
    final FlutterErrorDetails details = FlutterErrorDetails(
      exception: exception,
      stack: stackTrace,
      library: 'widgets library',
      context: ErrorDescription('building'),
    );
    FlutterError.reportError(details);
    return ErrorWidget.builder(details);
  }

  @override
  Widget build(BuildContext context, int index) {
    assert(builder != null);
    if (index < 0 || (childCount != null && index >= childCount)) return null;
    Widget child;
    try {
      child = builder(context, index);
    } catch (exception, stackTrace) {
      child = _createErrorWidget(exception, stackTrace);
    }
    if (child == null) return null;
    final Key key = child.key != null ? _SaltedValueKey(child.key) : null;
    if (addRepaintBoundaries) child = RepaintBoundary(child: child);
    if (addSemanticIndexes) {
      final int semanticIndex = semanticIndexCallback(child, index);
      if (semanticIndex != null)
        child = IndexedSemantics(index: semanticIndex + semanticIndexOffset, child: child);
    }
    if (addAutomaticKeepAlives) child = AutomaticKeepAlive(child: child);
    return KeyedSubtree(child: child, key: key);
  }

  @override
  void didFinishLayout(int _firstIndex, int _lastIndex) {
    // TODO: implement didFinishLayout
    super.didFinishLayout(_firstIndex, _lastIndex);
  }

  ///监听 在可见的列表中 显示的第一个位置和最后一个位置
  @override
  double estimateMaxScrollOffset(
      int _firstIndex, int _lastIndex, double _leadingScrollOffset, double _trailingScrollOffset) {
    // print(
    //     'firstIndex = $_firstIndex, lastIndex = $_lastIndex, leadingScrollOffset = $_leadingScrollOffset,'
    //     'trailingScrollOffset : $_trailingScrollOffset  ');

    //违章信息Listview滚动广播
    eventBus.fire(WzxxDataScrollEvent(_firstIndex, _lastIndex));

    return super.estimateMaxScrollOffset(
        _firstIndex, _lastIndex, _leadingScrollOffset, _trailingScrollOffset);
  }
}
