import 'package:flutter/material.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/utils/theme_utils.dart';

class LogisticsInformationItem extends StatefulWidget {
  final Color topColor;
  final Color centerColor;
  final Color bottomColor;
  final Color titleColor;
  final Color textColor;
  final String title;
  final String text;

  LogisticsInformationItem({
    this.topColor:Colours.app_main,
    this.centerColor:Colours.app_main,
    this.bottomColor:Colours.app_main,
    this.titleColor:Colours.time_axis_title,
    this.textColor:Colours.time_axis_text,
    this.title,
    this.text,
  });

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

class _LogisticsInformationItemState extends State<LogisticsInformationItem> {
  double item_height = 0.0;
  GlobalKey textKey = new GlobalKey();

  @override
  void initState() {
    super.initState();
    ///监听是否渲染完
    WidgetsBinding widgetsBinding = WidgetsBinding.instance;
    widgetsBinding.addPostFrameCallback((callback) {
      ///获取相应控件的size
      RenderObject renderObject = textKey.currentContext.findRenderObject();
      setState(() {
        item_height = renderObject.semanticBounds.size.height;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: ThemeUtils.getTabsBg(context),
      padding: EdgeInsets.only(left: 15, right: 15),
      child: Row(
        children: [
          Container(
            width: 10,
            height: item_height,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Expanded(
                    child: Container(
                  width: 0.9,
                  color: widget.topColor,
                )),
                Container(
                  height: 10,
                  width: 10,
                  decoration: BoxDecoration(
                    color: widget.centerColor,
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                  ),
                ),
                Expanded(
                    child: Container(
                  width: 0.9,
                  color: widget.bottomColor,
                )),
              ],
            ),
          ),

          ///右侧的文案
          Expanded(
            child: Padding(
              key: textKey,
              padding: const EdgeInsets.only(left: 20, top: 10, bottom: 10),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    widget.title,
                    style: TextStyle(fontSize: 14, color: widget.titleColor),
                  ),
                  SizedBox(height: 8,),
                  Text(
                    widget.text,
                    style: TextStyle(fontSize: 12, color: widget.textColor),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
