showSpeedDialog method

void showSpeedDialog(
  1. BuildContext context
)

Implementation

void showSpeedDialog(BuildContext context) {
  if (context.orientation == Orientation.landscape) {
    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          title: const Text(
            'Playback Speed',
            style: TextStyle(
              color: Colors.black,
              fontSize: 20,
              fontWeight: FontWeight.bold,
            ),
          ),
          content: SingleChildScrollView(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: _speeds
                  .map(
                    (speed) => InkWell(
                      onTap: () {
                        Navigator.pop(context);
                        final speedValue = double.parse(speed == "Normal"
                            ? "1.0"
                            : speed.replaceAll('x', ''));
                        setPlaybackSpeed(speedValue);
                      },
                      child: Padding(
                        padding: const EdgeInsets.symmetric(
                          vertical: 5,
                          horizontal: 10,
                        ),
                        child: Row(
                          children: [
                            playbackSpeed ==
                                    double.parse(speed == "Normal"
                                        ? "1.0"
                                        : speed.replaceAll('x', ''))
                                ? const Icon(
                                    Icons.check_box_rounded,
                                    color: Colors.blue,
                                  )
                                : const Icon(
                                    Icons.check_box_outline_blank,
                                    color: Colors.grey,
                                  ),
                            10.widthBox,
                            Text(speed),
                          ],
                        ),
                      ),
                    ),
                  )
                  .toList(),
            ),
          ),
        );
      },
    );
  } else {
    showModalBottomSheet(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(
          top: Radius.circular(10),
        ),
      ),
      isScrollControlled: true,
      builder: (context) {
        return Padding(
          padding: const EdgeInsets.all(10),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Text(
                'Playback Speed',
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                ),
              ),
              const Divider(),
              ListView.builder(
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                itemCount: _speeds.length,
                itemBuilder: (context, index) {
                  final speed = _speeds[index];
                  return InkWell(
                    onTap: () {
                      Navigator.pop(context);
                      final speedValue = double.parse(speed == "Normal"
                          ? "1.0"
                          : speed.replaceAll('x', ''));
                      setPlaybackSpeed(speedValue);
                    },
                    child: Padding(
                      padding: const EdgeInsets.symmetric(
                        vertical: 2,
                        horizontal: 5,
                      ),
                      child: Row(
                        children: [
                          playbackSpeed ==
                                  double.parse(speed == "Normal"
                                      ? "1.0"
                                      : speed.replaceAll('x', ''))
                              ? const Icon(
                                  Icons.check_box_rounded,
                                  color: Colors.blue,
                                )
                              : const Icon(
                                  Icons.check_box_outline_blank,
                                  color: Colors.grey,
                                ),
                          10.widthBox,
                          Expanded(child: Text(speed)),
                        ],
                      ),
                    ),
                  );
                },
              ),
            ],
          ),
        );
      },
    );
  }
}