Compare commits

..

1 Commits

Author SHA1 Message Date
9986f72e11 improve shortcut buttons. (#242) 2023-07-19 21:09:24 -07:00
7 changed files with 59 additions and 52 deletions

View File

@ -39,8 +39,9 @@ abstract class Constants {
static const String featureOpenStoryInWebView = 'open_story_in_web_view'; static const String featureOpenStoryInWebView = 'open_story_in_web_view';
static const String featureLogIn = 'log_in'; static const String featureLogIn = 'log_in';
static const String featurePinToTop = 'pin_to_top'; static const String featurePinToTop = 'pin_to_top';
static const String featureJumpUpButton = 'jump_up_button'; static const String featureJumpUpButton = 'jump_up_button_with_long_press';
static const String featureJumpDownButton = 'jump_down_button'; static const String featureJumpDownButton =
'jump_down_button_with_long_press';
static final String happyFace = <String>[ static final String happyFace = <String>[
'(๑•̀ㅂ•́)و✧', '(๑•̀ㅂ•́)و✧',

View File

@ -349,8 +349,8 @@ class CommentsCubit extends Cubit<CommentsState> {
init(useCommentCache: true); init(useCommentCache: true);
} }
/// Jump to next root level comment. /// Scroll to next root level comment.
void jump( void scrollToNextRoot(
ItemScrollController itemScrollController, ItemScrollController itemScrollController,
ItemPositionsListener itemPositionsListener, ItemPositionsListener itemPositionsListener,
) { ) {
@ -387,8 +387,8 @@ class CommentsCubit extends Cubit<CommentsState> {
} }
} }
/// Jump to previous root level comment. /// Scroll to previous root level comment.
void jumpUp( void scrollToPreviousRoot(
ItemScrollController itemScrollController, ItemScrollController itemScrollController,
ItemPositionsListener itemPositionsListener, ItemPositionsListener itemPositionsListener,
) { ) {

View File

@ -289,7 +289,9 @@ class HackiApp extends StatelessWidget {
child: MaterialApp( child: MaterialApp(
title: 'Hacki', title: 'Hacki',
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: useTrueDark ? trueDarkTheme : theme, theme: (useTrueDark ? trueDarkTheme : theme).copyWith(
useMaterial3: false,
),
navigatorKey: navigatorKey, navigatorKey: navigatorKey,
navigatorObservers: <NavigatorObserver>[ navigatorObservers: <NavigatorObserver>[
locator.get<RouteObserver<ModalRoute<dynamic>>>(), locator.get<RouteObserver<ModalRoute<dynamic>>>(),

View File

@ -32,30 +32,32 @@ class CustomFloatingActionButton extends StatelessWidget {
Icons.keyboard_arrow_up, Icons.keyboard_arrow_up,
color: Palette.white, color: Palette.white,
), ),
title: const Text('Jump to previous root level comment.'), title: const Text('Shortcut'),
description: const Text( description: const Text(
'''Tapping on this button will take you to the previous off-screen root level comment.''', '''Tapping on this button will take you to the previous off-screen root level comment.\n\nLong press on it to jump to the very beginning of this thread.''',
), ),
child: FloatingActionButton.small( child: InkWell(
backgroundColor: Theme.of(context).scaffoldBackgroundColor, onLongPress: () => itemScrollController.scrollTo(
index: 0,
duration: Durations.ms400,
),
child: FloatingActionButton.small(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
/// Randomly generated string as heroTag to prevent /// Randomly generated string as heroTag to prevent
/// default [FloatingActionButton] animation. /// default [FloatingActionButton] animation.
heroTag: UniqueKey().hashCode, heroTag: UniqueKey().hashCode,
onPressed: () { onPressed: () {
if (state.status == CommentsStatus.loading) return; HapticFeedbackUtil.selection();
context.read<CommentsCubit>().scrollToPreviousRoot(
HapticFeedbackUtil.selection(); itemScrollController,
context.read<CommentsCubit>().jumpUp( itemPositionsListener,
itemScrollController, );
itemPositionsListener, },
); child: Icon(
}, Icons.keyboard_arrow_up,
child: Icon( color: Theme.of(context).colorScheme.primary,
Icons.keyboard_arrow_up, ),
color: state.status == CommentsStatus.loading
? Palette.grey
: Theme.of(context).colorScheme.primary,
), ),
), ),
), ),
@ -65,29 +67,31 @@ class CustomFloatingActionButton extends StatelessWidget {
Icons.keyboard_arrow_down, Icons.keyboard_arrow_down,
color: Palette.white, color: Palette.white,
), ),
title: const Text('Jump to next root level comment.'), title: const Text('Shortcut'),
description: const Text( description: const Text(
'''Tapping on this button will take you to the next off-screen root level comment.''', '''Tapping on this button will take you to the next off-screen root level comment.\n\nLong press on it to jump to the end of this thread.''',
), ),
child: FloatingActionButton.small( child: InkWell(
backgroundColor: Theme.of(context).scaffoldBackgroundColor, onLongPress: () => itemScrollController.scrollTo(
index: state.comments.length,
duration: Durations.ms400,
),
child: FloatingActionButton.small(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
/// Same as above. /// Same as above.
heroTag: UniqueKey().hashCode, heroTag: UniqueKey().hashCode,
onPressed: () { onPressed: () {
if (state.status == CommentsStatus.loading) return; HapticFeedbackUtil.selection();
context.read<CommentsCubit>().scrollToNextRoot(
HapticFeedbackUtil.selection(); itemScrollController,
context.read<CommentsCubit>().jump( itemPositionsListener,
itemScrollController, );
itemPositionsListener, },
); child: Icon(
}, Icons.keyboard_arrow_down,
child: Icon( color: Theme.of(context).colorScheme.primary,
Icons.keyboard_arrow_down, ),
color: state.status == CommentsStatus.loading
? Palette.grey
: Theme.of(context).colorScheme.primary,
), ),
), ),
), ),

View File

@ -1414,4 +1414,4 @@ packages:
version: "3.1.2" version: "3.1.2"
sdks: sdks:
dart: ">=3.0.0 <4.0.0" dart: ">=3.0.0 <4.0.0"
flutter: ">=3.10.5" flutter: ">=3.10.6"

View File

@ -1,11 +1,11 @@
name: hacki name: hacki
description: A Hacker News reader. description: A Hacker News reader.
version: 1.8.1+117 version: 1.8.2+118
publish_to: none publish_to: none
environment: environment:
sdk: ">=3.0.0 <4.0.0" sdk: ">=3.0.0 <4.0.0"
flutter: "3.10.5" flutter: "3.10.6"
dependencies: dependencies:
adaptive_theme: ^3.2.0 adaptive_theme: ^3.2.0