import 'package:flutter/material.dart';
import 'package:linked_scroll_controller/linked_scroll_controller.dart';

import 'table_head.dart';
import 'table_body.dart';

class TableScrollable extends StatefulWidget {
  // 所有点位 31 天的车流量日统计数据，每天有 3 个数据：车流量、早高峰、晚高峰
  Map mapTableData; // 有 31 个元素，每个元素又是一个 Map：包含车流量、早高峰、晚高峰

  TableScrollable({
    @required this.mapTableData,
  });

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

class _TableScrollableState extends State<TableScrollable> {
  LinkedScrollControllerGroup _controllers;
  ScrollController _headController;
  ScrollController _bodyController;

  @override
  void initState() {
    super.initState();
    _controllers = LinkedScrollControllerGroup();
    _headController = _controllers.addAndGet();
    _bodyController = _controllers.addAndGet();
  }

  @override
  void dispose() {
    _headController.dispose();
    _bodyController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          TableHead(
            scrollController: _headController,
          ),
          Expanded(
            child: TableBody(
              scrollController: _bodyController,
              mapTableData: widget.mapTableData,
            ),
          ),
        ],
      ),
    );
  }
}
