import 'package:flutter/material.dart';

class SecondsPicker extends StatefulWidget {
  final int initialSeconds;
  final ValueChanged<int> onSecondsChanged;

  SecondsPicker({
    required this.initialSeconds,
    required this.onSecondsChanged,
  });

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

class _SecondsPickerState extends State<SecondsPicker> {
  late FixedExtentScrollController _scrollController;

  @override
  void initState() {
    super.initState();
    _scrollController = FixedExtentScrollController(
      initialItem: widget.initialSeconds,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 120,
      color: Colors.white,
      child: ListWheelScrollView.useDelegate(
        controller: _scrollController,
        itemExtent: 48,
        onSelectedItemChanged: (index) {
          widget.onSecondsChanged(index);
        },
        physics: const FixedExtentScrollPhysics(),
        childDelegate: ListWheelChildBuilderDelegate(
          builder: (context, index) {
            return Center(
              child: Text(
                '$index sec',
                style: const TextStyle(fontSize: 24),
              ),
            );
          },
        ),
      ),
    );
  }
}
