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

feat: allow duration to be configured on selection list. #117

Merged
merged 7 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
- fix: `NesRunningText` was not disposing its controller.
- feat: add `NesRunningTextLines`.
- feat: add `NesPulser`.
- feat: allow duration to be configured on selection list.

# 0.12.1
- fix: theme lerp causing error on null access.


# 0.12.0
- feat: adding `NesBlinker`.
- fix: `NesRunningText` would not update its text.
Expand Down
1 change: 1 addition & 0 deletions example/lib/gallery/sections/selection_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class _SelectionListSectionState extends State<SelectionListSection> {
child: NesSelectionList(
initialIndex: _horizontal,
axis: Axis.horizontal,
tickerDuration: const Duration(milliseconds: 100),
children: const [
Text('Yes'),
Text('No'),
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/nes_blinker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ class NesBlinker extends Phased<bool> {
NesBlinker({
super.key,
required this.child,
this.tickerDuration = const Duration(seconds: 1),
}) : super(
state: PhasedState<bool>(
values: [true, false],
ticker: const Duration(seconds: 1),
ticker: tickerDuration,
),
);

/// Duration of ticker, it changes the blink speed.
final Duration? tickerDuration;

/// The child widget to blink.
final Widget child;

Expand Down
8 changes: 8 additions & 0 deletions lib/src/widgets/nes_selection_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class NesSelectionList extends StatefulWidget {
this.canAutoFocus = true,
this.focusNode,
this.onCancelSelection,
this.tickerDuration,
this.canCancelSelection = true,
}) : assert(
initialIndex == null || initialIndex < children.length,
Expand Down Expand Up @@ -58,6 +59,9 @@ class NesSelectionList extends StatefulWidget {
/// This can be useful in lists that are the "root" of a page or section.
final bool canCancelSelection;

/// Duration of ticker, it changes the blink speed.
final Duration? tickerDuration;

@override
State<NesSelectionList> createState() => _NesSelectionListState();
}
Expand Down Expand Up @@ -171,6 +175,7 @@ class _NesSelectionListState extends State<NesSelectionList> {
for (var i = 0; i < widget.children.length; i++)
_SelectionItem(
markerKey: _markerKey,
tickerDuration: widget.tickerDuration,
onTap: () {
if (_focusNode.hasFocus) {
setState(() {
Expand Down Expand Up @@ -230,6 +235,7 @@ class _SelectionItem extends StatelessWidget {
required this.markerSize,
required this.itemMinHeight,
required this.hasFocus,
this.tickerDuration,
});

final Key markerKey;
Expand All @@ -242,12 +248,14 @@ class _SelectionItem extends StatelessWidget {
final Widget child;
final double itemMinHeight;
final bool hasFocus;
final Duration? tickerDuration;

@override
Widget build(BuildContext context) {
final itemMarker = cursor && hasFocus
? NesBlinker(
key: markerKey,
tickerDuration: tickerDuration,
child: marker,
)
: (selected ? marker : null);
Expand Down