From de2453977bf9c20b92ef9fe3e427a10176bff0e0 Mon Sep 17 00:00:00 2001 From: Erick Date: Thu, 21 Dec 2023 11:17:52 -0300 Subject: [PATCH] feat: add nes blinker (#108) * feat: adding blinker * examples and changelog * examples and changelog * fix lint --- CHANGELOG.md | 3 +++ example/lib/gallery/gallery_page.dart | 2 ++ example/lib/gallery/sections/effects.dart | 31 ++++++++++++++++++++++ example/lib/gallery/sections/sections.dart | 1 + lib/src/widgets/nes_blinker.dart | 30 +++++++++++++++++++++ lib/src/widgets/nes_selection_list.dart | 26 +----------------- lib/src/widgets/widgets.dart | 1 + 7 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 example/lib/gallery/sections/effects.dart create mode 100644 lib/src/widgets/nes_blinker.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e4986..8b7c5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.12.0 + - feat: adding `NesBlinker`. + # 0.11.0 - feat: add ability to customize `NesContainer`s pixel sizes. - feat: add ability to customize `NesButton`s pixel sizes. diff --git a/example/lib/gallery/gallery_page.dart b/example/lib/gallery/gallery_page.dart index f61e07d..a8f3df2 100644 --- a/example/lib/gallery/gallery_page.dart +++ b/example/lib/gallery/gallery_page.dart @@ -37,6 +37,8 @@ class GalleryPage extends StatelessWidget { const SizedBox(height: 32), const RunningTextSection(), const SizedBox(height: 32), + const EffectsSection(), + const SizedBox(height: 32), const LoadingIndicatorsSection(), const SizedBox(height: 32), const TooltipsSection(), diff --git a/example/lib/gallery/sections/effects.dart b/example/lib/gallery/sections/effects.dart new file mode 100644 index 0000000..9559e9b --- /dev/null +++ b/example/lib/gallery/sections/effects.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:nes_ui/nes_ui.dart'; + +class EffectsSection extends StatelessWidget { + const EffectsSection({super.key}); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Effects', + style: theme.textTheme.displayMedium, + ), + const SizedBox(height: 16), + Wrap( + children: [ + SizedBox( + height: 40, + child: NesBlinker( + child: const Text('NES Blinker'), + ), + ), + ], + ), + ], + ); + } +} diff --git a/example/lib/gallery/sections/sections.dart b/example/lib/gallery/sections/sections.dart index c6540f8..b55414e 100644 --- a/example/lib/gallery/sections/sections.dart +++ b/example/lib/gallery/sections/sections.dart @@ -4,6 +4,7 @@ export 'containers.dart'; export 'custom_extensions.dart'; export 'dialogs.dart'; export 'drop_shadows.dart'; +export 'effects.dart'; export 'file_explorer.dart'; export 'icon_badges.dart'; export 'icon_buttons.dart'; diff --git a/lib/src/widgets/nes_blinker.dart b/lib/src/widgets/nes_blinker.dart new file mode 100644 index 0000000..ad4c4f1 --- /dev/null +++ b/lib/src/widgets/nes_blinker.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; +import 'package:phased/phased.dart'; + +/// {@template nes_blinker} +/// A widget that blinks its child. +/// {@endtemplate} +class NesBlinker extends Phased { + /// {@macro nes_blinker} + NesBlinker({ + super.key, + required this.child, + }) : super( + state: PhasedState( + values: [true, false], + ticker: const Duration(seconds: 1), + ), + ); + + /// The child widget to blink. + final Widget child; + + @override + Widget build(BuildContext context) { + if (state.value) { + return child; + } else { + return const SizedBox(); + } + } +} diff --git a/lib/src/widgets/nes_selection_list.dart b/lib/src/widgets/nes_selection_list.dart index c271b25..bf8b2fa 100644 --- a/lib/src/widgets/nes_selection_list.dart +++ b/lib/src/widgets/nes_selection_list.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:nes_ui/nes_ui.dart'; -import 'package:phased/phased.dart'; /// {@template nes_selection_list} /// @@ -219,29 +218,6 @@ class _NesSelectionListState extends State { } } -class _Blinker extends Phased { - _Blinker({ - super.key, - required this.child, - }) : super( - state: PhasedState( - values: [true, false], - ticker: const Duration(seconds: 1), - ), - ); - - final Widget child; - - @override - Widget build(BuildContext context) { - if (state.value) { - return child; - } else { - return const SizedBox(); - } - } -} - class _SelectionItem extends StatelessWidget { const _SelectionItem({ required this.markerKey, @@ -270,7 +246,7 @@ class _SelectionItem extends StatelessWidget { @override Widget build(BuildContext context) { final itemMarker = cursor && hasFocus - ? _Blinker( + ? NesBlinker( key: markerKey, child: marker, ) diff --git a/lib/src/widgets/widgets.dart b/lib/src/widgets/widgets.dart index 809346e..2ee6ce1 100644 --- a/lib/src/widgets/widgets.dart +++ b/lib/src/widgets/widgets.dart @@ -1,4 +1,5 @@ export 'dialogs/dialogs.dart'; +export 'nes_blinker.dart'; export 'nes_button.dart'; export 'nes_check_box.dart'; export 'nes_container.dart';