import 'package:aitrainer_app/util/trans.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class NumberPickerWidget extends StatefulWidget {
  final Function(double) onChange;
  final int minValue;
  final int maxValue;
  final int initalValue;
  final String unit;
  final Color color;

  const NumberPickerWidget({Key key, this.minValue, this.maxValue, this.initalValue, this.unit, this.color, this.onChange})
      : super(key: key);
  @override
  _NumberPickerWidgetState createState() => _NumberPickerWidgetState();
}

class _NumberPickerWidgetState extends State<NumberPickerWidget> with Trans {
  Widget durationPicker({bool inSeconds = false, bool inHundredths = false}) {
    double value = 0;
    return CupertinoPicker(
      scrollController: FixedExtentScrollController(initialItem: widget.initalValue),
      backgroundColor: Colors.transparent,
      onSelectedItemChanged: (x) {
        currentData = x.toDouble();
        value = x.toDouble();
        //print("sec" + seconds.toStringAsFixed(2));
        setState(() {});
        widget.onChange(value);
      },
      children: List.generate(widget.maxValue, (index) => Text('$index ' + widget.unit, style: TextStyle(color: widget.color))),
      itemExtent: 40,
    );
  }

  double currentData = 0;
  @override
  Widget build(BuildContext context) {
    setContext(context);
    return Container(
      //color: Colors.white24,
      width: MediaQuery.of(context).size.width * .45,
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 16.0),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              color: Colors.transparent,
              width: MediaQuery.of(context).size.width * .3,
              child: Center(
                child: Container(
                    color: Colors.transparent,
                    width: MediaQuery.of(context).size.width * 0.95,
                    height: MediaQuery.of(context).size.height * 0.25,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Expanded(child: durationPicker()),
                      ],
                    )),
              ),
            ),
          ],
        ),
      ),
    );
  }
}