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 shortcut key "ctrl + s" for saving projects on the go. #493

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions lib/common/utils.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/utils/utils.dart';
import 'package:apidash/widgets/widgets.dart';

Expand All @@ -18,3 +20,14 @@ Future<void> saveCollection(
sm.hideCurrentSnackBar();
sm.showSnackBar(getSnackBar(message, small: false));
}

Future<void> saveData(BuildContext context, WidgetRef ref) async {
final overlayWidget = OverlayWidgetTemplate(context: context);
overlayWidget.show(widget: const SavingOverlay(saveCompleted: false));
await ref.read(collectionStateNotifierProvider.notifier).saveData();
await ref.read(environmentsStateNotifierProvider.notifier).saveEnvironments();
overlayWidget.hide();
overlayWidget.show(widget: const SavingOverlay(saveCompleted: true));
await Future.delayed(const Duration(seconds: 1));
overlayWidget.hide();
}
18 changes: 2 additions & 16 deletions lib/screens/common_widgets/sidebar_save_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,20 @@ import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:apidash/consts.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart';
import '../../common/utils.dart';

class SaveButton extends ConsumerWidget {
const SaveButton({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final overlayWidget = OverlayWidgetTemplate(context: context);
final savingData = ref.watch(saveDataStateProvider);
final hasUnsavedChanges = ref.watch(hasUnsavedChangesProvider);
return TextButton.icon(
onPressed: (savingData || !hasUnsavedChanges)
? null
: () async {
overlayWidget.show(
widget: const SavingOverlay(saveCompleted: false));

await ref
.read(collectionStateNotifierProvider.notifier)
.saveData();
await ref
.read(environmentsStateNotifierProvider.notifier)
.saveEnvironments();
overlayWidget.hide();
overlayWidget.show(
widget: const SavingOverlay(saveCompleted: true));
await Future.delayed(const Duration(seconds: 1));
overlayWidget.hide();
await saveData(context, ref);
},
icon: const Icon(
Icons.save,
Expand Down
233 changes: 135 additions & 98 deletions lib/screens/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart';
Expand All @@ -10,120 +11,156 @@ import 'home_page/home_page.dart';
import 'history/history_page.dart';
import 'settings_page.dart';

class SaveIntent extends Intent {}

class Dashboard extends ConsumerWidget {
const Dashboard({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {

bool isControlPressed = false;
void onKey(KeyEvent event) {
if (event is KeyDownEvent) {
if (event.logicalKey == LogicalKeyboardKey.controlLeft ||
event.logicalKey == LogicalKeyboardKey.controlRight) {
isControlPressed = true;
}
if (event.logicalKey == LogicalKeyboardKey.keyS && isControlPressed) {
SaveButton.saveData(context, ref);
}
}
if (event is KeyUpEvent) {
if (event.logicalKey == LogicalKeyboardKey.controlLeft ||
event.logicalKey == LogicalKeyboardKey.controlRight) {
isControlPressed = false;
}
}
}
FocusNode _focusNode = FocusNode();
final railIdx = ref.watch(navRailIndexStateProvider);
return Scaffold(
body: SafeArea(
child: Row(
children: <Widget>[
Column(
children: [
SizedBox(
height: kIsMacOS ? 32.0 : 16.0,
width: 64,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
isSelected: railIdx == 0,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 0;
},
icon: const Icon(Icons.auto_awesome_mosaic_outlined),
selectedIcon: const Icon(Icons.auto_awesome_mosaic),
),
Text(
'Requests',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 1,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 1;
},
icon: const Icon(Icons.laptop_windows_outlined),
selectedIcon: const Icon(Icons.laptop_windows),
),
Text(
'Variables',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 2,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 2;
},
icon: const Icon(Icons.history_outlined),
selectedIcon: const Icon(Icons.history_rounded),
),
Text(
'History',
style: Theme.of(context).textTheme.labelSmall,
),
],
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
body: KeyboardListener(
autofocus: true,
onKeyEvent: onKey,
focusNode: _focusNode,
child: SafeArea(
child: Row(
children: <Widget>[
Column(
children: [
SizedBox(
height: kIsMacOS ? 32.0 : 16.0,
width: 64,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
selectedIcon: Icons.help,
icon: Icons.help_outline,
label: 'About',
showLabel: false,
isCompact: true,
onTap: () {
showAboutAppDialog(context);
},
),
IconButton(
isSelected: railIdx == 0,
onPressed: () {
ref
.read(navRailIndexStateProvider.notifier)
.state = 0;
},
icon:
const Icon(Icons.auto_awesome_mosaic_outlined),
selectedIcon: const Icon(Icons.auto_awesome_mosaic),
),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
buttonIdx: 3,
selectedIcon: Icons.settings,
icon: Icons.settings_outlined,
label: 'Settings',
showLabel: false,
isCompact: true,
),
Text(
'Requests',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 1,
onPressed: () {
ref
.read(navRailIndexStateProvider.notifier)
.state = 1;
},
icon: const Icon(Icons.laptop_windows_outlined),
selectedIcon: const Icon(Icons.laptop_windows),
),
Text(
'Variables',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 2,
onPressed: () {
ref
.read(navRailIndexStateProvider.notifier)
.state = 2;
},
icon: const Icon(Icons.history_outlined),
selectedIcon: const Icon(Icons.history_rounded),
),
Text(
'History',
style: Theme.of(context).textTheme.labelSmall,
),
],
),
),
],
),
VerticalDivider(
thickness: 1,
width: 1,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
Expanded(
child: IndexedStack(
alignment: AlignmentDirectional.topCenter,
index: railIdx,
children: const [
HomePage(),
EnvironmentPage(),
HistoryPage(),
SettingsPage(),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
selectedIcon: Icons.help,
icon: Icons.help_outline,
label: 'About',
showLabel: false,
isCompact: true,
onTap: () {
showAboutAppDialog(context);
},
),
),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
buttonIdx: 3,
selectedIcon: Icons.settings,
icon: Icons.settings_outlined,
label: 'Settings',
showLabel: false,
isCompact: true,
),
),
],
),
),
],
),
)
],
VerticalDivider(
thickness: 1,
width: 1,
color:
Theme.of(context).colorScheme.surfaceContainerHighest,
),
Expanded(
child: IndexedStack(
alignment: AlignmentDirectional.topCenter,
index: railIdx,
children: const [
HomePage(),
EnvironmentPage(),
HistoryPage(),
SettingsPage(),
],
),
)
],
),
),
),
);
}
}