
import 'package:flutter/material.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/widgets/smooth_star_rating.dart';

class StarItem extends StatelessWidget {

  const StarItem({
    Key key,
    this.onTap,
    @required this.title,
    this.maxLines: 1,
    this.starRating,
    this.onRatingChanged,
  }): super(key: key);

  final GestureTapCallback onTap;
  final Function(double) onRatingChanged;
  final String title;
  final int maxLines;
  final double starRating;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.fromLTRB(15, 15.0, 15.0, 15.0),
        constraints: BoxConstraints(
            maxHeight: double.infinity,
            minHeight: 50.0
        ),
        width: double.infinity,
        // decoration: BoxDecoration(
        //     color: Colors.white,
        //     border: Border(
        //       bottom: Divider.createBorderSide(context, width: 0.6),
        //     )
        // ),
        child: Row(
          //为了数字类文字居中
          crossAxisAlignment: maxLines == 1 ? CrossAxisAlignment.center : CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              // flex: 4,
              child: Text(title),
            ),
            SmoothStarRating(
              iconSelected:LoadAssetImage("icon_star_selected",
                  width: 18, height: 18),
              iconNormal: LoadAssetImage("icon_star_normal",
                  width: 18, height: 18),
              allowHalfRating: false,
              onRatingChanged: onRatingChanged,
              starCount: 5,
              rating: starRating,
              size: 30,
              color: Color(0xFFF4A22D),
              borderColor: Colours.text_gray_c,
            )
          ],
        ),
      ),
    );
  }
}

class StarItemShow extends StatelessWidget {

  const StarItemShow({
    Key key,
    this.maxLines: 1,
    this.starRating,
  }): super(key: key);

  final int maxLines;
  final double starRating;

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return InkWell(
      child: Container(
        // padding: const EdgeInsets.fromLTRB(15, 15.0, 0, 15.0),
        constraints: BoxConstraints(
            maxHeight: 20.0,
            minHeight: 20.0
        ),
        width: width*0.4,
        // decoration: BoxDecoration(
        //     color: Colors.white,
        //     border: Border(
        //       bottom: Divider.createBorderSide(context, width: 0.6),
        //     )
        // ),
        child: Row(
          //为了数字类文字居中
          crossAxisAlignment: maxLines == 1 ? CrossAxisAlignment.center : CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            SmoothStarRating(
              paddingLeft:2.0,
              paddingRight:2.0,
              iconSelected:LoadAssetImage("icon_star_selected",
                  width: 14, height: 14),
              iconNormal: LoadAssetImage("icon_star_normal",
                  width: 14, height: 14),
              allowHalfRating: false,
              starCount: 5,
              rating: starRating,
              size: 15,
              color: Color(0xFFF4A22D),
              borderColor: Colours.text_gray_c,
            )
          ],
        ),
      ),
    );
  }
}
