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 tab view #327

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
20 changes: 9 additions & 11 deletions lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,24 @@ const kPv8 = EdgeInsets.symmetric(vertical: 8);
const kPv10 = EdgeInsets.symmetric(vertical: 10);
const kPv20 = EdgeInsets.symmetric(vertical: 20);
const kPh2 = EdgeInsets.symmetric(horizontal: 2);
const kPt24o8 = EdgeInsets.only(top: 24, left: 8.0, right: 8.0, bottom: 8.0);
const kPt24 = EdgeInsets.only(top: 24);
const kPt8 = EdgeInsets.only(top: 8);
const kPt28o8 = EdgeInsets.only(top: 28, left: 8.0, right: 8.0, bottom: 8.0);
const kPt5o10 =
EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 10.0);
const kPh4 = EdgeInsets.symmetric(horizontal: 4);
const kPh8 = EdgeInsets.symmetric(horizontal: 8);
const kPh20 = EdgeInsets.symmetric(
horizontal: 20,
);
// const kPh20t3 = EdgeInsets.only(
const kPh12 = EdgeInsets.symmetric(horizontal: 12);
const kPh20 = EdgeInsets.symmetric(horizontal: 20);
const kPh24 = EdgeInsets.symmetric(horizontal: 24);
const kPh20t40 = EdgeInsets.only(
left: 20,
right: 20,
top: 40,
top: 3
);
const kPs0o6 = EdgeInsets.only(
left: 0,
Expand All @@ -138,25 +144,17 @@ const kPh60 = EdgeInsets.symmetric(horizontal: 60);
const kPh60v60 = EdgeInsets.symmetric(vertical: 60, horizontal: 60);
const kP24CollectionPane = EdgeInsets.only(
top: 24,
left: 4.0,
//right: 4.0,
// bottom: 8.0,
left: 8.0,
);
const kP8CollectionPane = EdgeInsets.only(
top: 8.0,
left: 4.0,
//right: 4.0,
// bottom: 8.0,
);
const kPt8 = EdgeInsets.only(
top: 8,
);
const kPt20 = EdgeInsets.only(
top: 20,
);
const kPt24 = EdgeInsets.only(
top: 24,
);
const kPt28 = EdgeInsets.only(
top: 28,
);
Expand Down
25 changes: 25 additions & 0 deletions lib/providers/collection_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ final requestSequenceProvider = StateProvider<List<String>>((ref) {
return ids ?? [];
});

final requestTabSequenceProvider = StateProvider<List<String>>((ref) {
var ids = hiveHandler.getTabIds();
return ids ?? [];
});

final StateNotifierProvider<CollectionStateNotifier, Map<String, RequestModel>?>
collectionStateNotifierProvider =
StateNotifierProvider((ref) => CollectionStateNotifier(ref, hiveHandler));
Expand All @@ -37,6 +42,9 @@ class CollectionStateNotifier
ref.read(requestSequenceProvider.notifier).state = [
state!.keys.first,
];
ref.read(requestTabSequenceProvider.notifier).state = [
state!.keys.first,
];
}
ref.read(selectedIdStateProvider.notifier).state =
ref.read(requestSequenceProvider)[0];
Expand Down Expand Up @@ -81,10 +89,21 @@ class CollectionStateNotifier
ref
.read(requestSequenceProvider.notifier)
.update((state) => [id, ...state]);
ref
.read(requestTabSequenceProvider.notifier)
.update((state) => [id, ...state]);

ref.read(selectedIdStateProvider.notifier).state = newRequestModel.id;
ref.read(hasUnsavedChangesProvider.notifier).state = true;
}

void reorderTab(int oldIdx, int newIdx){
var itemIds = ref.read(requestTabSequenceProvider);
final itemId = itemIds.removeAt(oldIdx);
itemIds.insert(newIdx, itemId);
ref.read(requestTabSequenceProvider.notifier).state = [...itemIds];
}

void reorder(int oldIdx, int newIdx) {
var itemIds = ref.read(requestSequenceProvider);
final itemId = itemIds.removeAt(oldIdx);
Expand All @@ -108,6 +127,10 @@ class CollectionStateNotifier
newId = null;
}

final tabs = ref.read(requestTabSequenceProvider);
tabs.remove(id);
ref.read(requestTabSequenceProvider.notifier).state = [...tabs];

ref.read(selectedIdStateProvider.notifier).state = newId;

var map = {...state!};
Expand Down Expand Up @@ -353,7 +376,9 @@ class CollectionStateNotifier
ref.read(saveDataStateProvider.notifier).state = true;
final saveResponse = ref.read(settingsProvider).saveResponses;
final ids = ref.read(requestSequenceProvider);
final tabIds = ref.read(requestTabSequenceProvider);
await hiveHandler.setIds(ids);
await hiveHandler.setTabIds(tabIds);
for (var id in ids) {
await hiveHandler.setRequestModel(
id,
Expand Down
209 changes: 106 additions & 103 deletions lib/screens/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import 'package:apidash/providers/providers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart';
import 'package:apidash/consts.dart';
import 'common_widgets/common_widgets.dart';
import 'envvar/environment_page.dart';

import 'home_page/home_page.dart';
import 'history/history_page.dart';
import 'settings_page.dart';

class Dashboard extends ConsumerWidget {
Expand All @@ -17,112 +13,119 @@ class Dashboard extends ConsumerWidget {
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,
),
],
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: MediaQuery.of(context).size.width,
height: 30,
color: Theme.of(context).colorScheme.surfaceVariant,
alignment: Alignment.center,
child: const Text(
'API Dash',
style: TextStyle(
fontWeight: FontWeight.bold,
),
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);
},
),
),
Expanded(
child: Row(
children: <Widget>[
SizedBox(
width: 64,
child: Column(
children: [
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,
),
],
),
),
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,
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: bottomButton(context, ref, railIdx, 1,
Icons.help, Icons.help_outline),
),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: bottomButton(context, ref, railIdx, 2,
Icons.settings, Icons.settings_outlined),
),
],
),
),
),
],
],
),
),
),
],
),
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(),
VerticalDivider(
thickness: 1,
width: 1,
color: Theme.of(context).colorScheme.surfaceVariant,
),
Expanded(
child: IndexedStack(
alignment: AlignmentDirectional.topCenter,
index: railIdx,
children: const [
HomePage(),
SettingsPage(),
],
),
)
],
),
)
),
],
),
),
);
}

TextButton bottomButton(
BuildContext context,
WidgetRef ref,
int railIdx,
int buttonIdx,
IconData selectedIcon,
IconData icon,
) {
bool isSelected = railIdx == buttonIdx;
return TextButton(
style: isSelected
? TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
)
: null,
onPressed: isSelected
? null
: () {
ref.read(navRailIndexStateProvider.notifier).state = buttonIdx;
},
child: Icon(
isSelected ? selectedIcon : icon,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
);
}
}
10 changes: 6 additions & 4 deletions lib/screens/home_page/collection_pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class CollectionPane extends ConsumerWidget {
);
}
return Padding(
padding: (!context.isMediumWindow && kIsMacOS
? kP24CollectionPane
: kP8CollectionPane) +
(context.isMediumWindow ? kPb70 : EdgeInsets.zero),
padding: kP8CollectionPane,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expand Down Expand Up @@ -221,6 +218,11 @@ class RequestItem extends ConsumerWidget {
editRequestId: editRequestId,
onTap: () {
ref.read(selectedIdStateProvider.notifier).state = id;
final tabs = ref.read(requestTabSequenceProvider);
if(!tabs.contains(id)){
tabs.add(id);
ref.read(requestTabSequenceProvider.notifier).state = [...tabs];
}
kHomeScaffoldKey.currentState?.closeDrawer();
},
// onDoubleTap: () {
Expand Down
Loading