Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added seek forward and rewind buttons #717

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

punit1111
Copy link

@punit1111 punit1111 commented Mar 28, 2023

  • double tap or click to seek forward or rewind back 10 seconds
  • seek forward and rewind buttons added to video controls screen
    are there other controls? #715

@diegotori
Copy link
Collaborator

@punit1111 Thank you for your PR.

Please re-sync your changes with the latest changes in master.

@punit1111
Copy link
Author

punit1111 commented Jul 3, 2023

@punit1111 Thank you for your PR.

Please re-sync your changes with the latest changes in master.

@diegotori re-sync done please review the PR

Thank you

Comment on lines 361 to 368
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekRewind,
onDoublePressed: _seekRewind,
icon: Icons.fast_rewind,
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SeekRewindButtons between line 361-368 and 388-395 can be reusable. Please extract them to a Widget _buildSeekRewindButton({bool isSeekForward = true}).

Comment on lines 836 to 854
void _seekForward() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds + 10,
),
);
});
}

void _seekRewind() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds - 10,
),
);
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code:

Suggested change
void _seekForward() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds + 10,
),
);
});
}
void _seekRewind() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds - 10,
),
);
});
}
void _seekTo({int seconds = 10}) {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds + seconds,
),
);
});
}
void _seekForward() => _seekTo();
void _seekRewind() => _seekTo(seconds: -10);

Comment on lines 375 to 421
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekRewind,
onDoublePressed: _seekRewind,
icon: Icons.fast_rewind,
),
GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;
});
} else {
_cancelAndRestartTimer();
}
} else {
_playPause();

setState(() {
notifier.hideStuff = true;
});
}
},
child: CenterPlayButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
),
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekForward,
onDoublePressed: _seekForward,
icon: Icons.fast_forward,
),
],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code from the other file: lib/src/cupertino/cupertino_controls.dart

@punit1111
Copy link
Author

@maherjaafar requested changes are done. please review the PR

Thank you

Comment on lines 54 to 63
SeekRewindButton _buildSeekRewindButton({bool isSeekForward = true}) {
return SeekRewindButton(
backgroundColor: backgroundColor,
iconColor: iconColor,
show: showSeekButton,
onPressed: isSeekForward ? seekForward : seekRewind,
onDoublePressed: isSeekForward ? seekForward : seekRewind,
icon: isSeekForward ? Icons.fast_forward : Icons.fast_rewind,
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use methods to return widgets. Instead you can simply add SeekRewindButton as part of your Row children.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

earlier it was inside a Row children. it's extracted into method as changes requested #717 (comment)

Copy link
Collaborator

@diegotori diegotori Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maherjaafar just an FYI, according to this issue and the official documentation regarding this subject, large Widgets should be spun off into new ones instead of methods that return them.

That way, you'll be able to create them as consts, thus increasing performance since they won't have to be re-built when build is called again.

@punit1111 sorry for the extra work, but these widgets should ultimately be extracted as new StatelessWidgets instead of being computed from a method.

Please let me know if this clears up things.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diegotori SeekRewindButton is already extracted as Stateless Widget lib/src/seek_rewind_button.dart

Copy link
Collaborator

@diegotori diegotori Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@punit1111 that is true, but instead of creating it from _buildSeekRewindButton, you should just replace those calls with the actual widget:

Change this:

_buildSeekRewindButton(isSeekForward: true),

to this:

SeekRewindButton(
      backgroundColor: backgroundColor,
      iconColor: iconColor,
      show: showSeekButton,
      onPressed: seekForward,
      onDoublePressed: seekForward,
      icon: Icons.fast_forward,
    )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do likewise for the other places where that method is being called from.

@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';

class SeekRewindButton extends StatefulWidget {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be renamed to SeekControlButton, so that it better reflects its stated purpose.

That way, you can create buttons that just configure that widget for its specific purpose:

class SeekRewindButton extends StatefulWidget {
   const SeekRewindButton({
     super.key,
    required this.backgroundColor,
    this.iconColor,
    required this.show,
    this.onPressed,
    this.onDoublePressed,
    this.icon = const Icons.fast_rewind,
   });
   
  final Color backgroundColor;
  final Color? iconColor;
  final bool show;
  final VoidCallback? onPressed;
  final VoidCallback? onDoublePressed;
  final IconData icon;
   
   Widget build(BuildContext context) {
     return SeekControlButton(
       backgroundColor: backgroundColor,
       iconColor: iconColor,
       show: show,
       icon: icon,
       onPressed: onPressed,
       onDoublePressed: onDoublePressed,
     );
   }
}

Do likewise for the fast-forward button: (i.e. SeekFastForwardButton).

final bool show;
final VoidCallback? onPressed;
final VoidCallback? onDoublePressed;
final IconData? icon;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If required, make it non-nullable.

@punit1111
Copy link
Author

Hi @diegotori

please review the Changes and let me know if anything needs to be fixed

Thank you

Comment on lines -363 to -370
child: CenterPlayButton(
backgroundColor: widget.backgroundColor,
iconColor: widget.iconColor,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cupertino controls already have the seek-forward and rewind buttons in the seek bar (i.e. the ones that rewind and fast-forward by 15 seconds).

As a result, this change should only apply to Material based widgets.

Do this for the other new widgets added in this PR, since they should only apply to Material.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @diegotori

requested changes done please review

Thank you

Copy link
Collaborator

@diegotori diegotori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@diegotori
Copy link
Collaborator

@maherjaafar please give this PR one last look before I can finalize this change.

Thanks.

@ameya730
Copy link

Hi,
Any update on when this branch will be pushed.
Regards,
Ameya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants