Update Dashboard NavigationRail

This commit is contained in:
Ashita Prasad
2023-10-08 02:39:34 +05:30
parent ee264bac36
commit adb14c22c7
2 changed files with 85 additions and 55 deletions

View File

@ -1,11 +1,12 @@
import 'package:apidash/consts.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final navRailIndexStateProvider = StateProvider<int?>((ref) => 0);
final navRailIndexStateProvider = StateProvider<int>((ref) => 0);
final activeIdStateProvider = StateProvider<String?>((ref) => null);
final activeIdEditStateProvider = StateProvider<String?>((ref) => null);
final sentRequestIdStateProvider = StateProvider<String?>((ref) => null);
final codePaneVisibleStateProvider = StateProvider<bool>((ref) => false);
final saveDataStateProvider = StateProvider<bool>((ref) => false);
final clearDataStateProvider = StateProvider<bool>((ref) => false);
final codegenLanguageStateProvider = StateProvider<CodegenLanguage>((ref) => CodegenLanguage.dartHttp);
final codegenLanguageStateProvider =
StateProvider<CodegenLanguage>((ref) => CodegenLanguage.dartHttp);

View File

@ -21,61 +21,62 @@ class _DashboardState extends ConsumerState<Dashboard> {
body: SafeArea(
child: Row(
children: <Widget>[
NavigationRail(
selectedIndex: railIdx,
groupAlignment: -1.0,
onDestinationSelected: (int index) {
setState(() {
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)
.update((state) => index);
});
.update((state) => 0);
},
labelType: NavigationRailLabelType.all,
leading: SizedBox(height: kIsMacOS ? 24.0 : 8.0),
trailing: Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: TextButton(
style: (railIdx == null)
? TextButton.styleFrom(
backgroundColor: Theme.of(context)
.colorScheme
.secondaryContainer,
)
: null,
onPressed: (railIdx == null)
? null
: () {
ref
.read(navRailIndexStateProvider.notifier)
.update((state) => null);
},
child: Icon(
(railIdx == null)
? Icons.settings
: Icons.settings_outlined,
color: Theme.of(context).colorScheme.onSurfaceVariant,
icon: const Icon(Icons.auto_awesome_mosaic_outlined),
selectedIcon: const Icon(Icons.auto_awesome_mosaic),
),
),
),
),
),
destinations: const <NavigationRailDestination>[
NavigationRailDestination(
icon: Icon(Icons.home_outlined),
selectedIcon: Icon(Icons.home),
label: Text('Home'),
),
NavigationRailDestination(
icon: Icon(Icons.auto_awesome_mosaic_outlined),
selectedIcon: Icon(Icons.auto_awesome_mosaic),
label: Text('Requests'),
Text(
'Requests',
style: Theme.of(context).textTheme.labelSmall,
),
],
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: bottomButton(context, railIdx, 1, Icons.help,
Icons.help_outline),
),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: bottomButton(context, railIdx, 2, Icons.settings,
Icons.settings_outlined),
),
],
),
),
],
// destinations: const <NavigationRailDestination>[
// // NavigationRailDestination(
// // icon: Icon(Icons.home_outlined),
// // selectedIcon: Icon(Icons.home),
// // label: Text('Home'),
// // ),
// NavigationRailDestination(
// icon: Icon(Icons.auto_awesome_mosaic_outlined),
// selectedIcon: Icon(Icons.auto_awesome_mosaic),
// label: Text('Requests'),
// ),
// ],
),
VerticalDivider(
thickness: 1,
width: 1,
@ -84,11 +85,11 @@ class _DashboardState extends ConsumerState<Dashboard> {
Expanded(
child: IndexedStack(
alignment: AlignmentDirectional.topCenter,
index: railIdx == null ? 0 : railIdx + 1,
index: railIdx,
children: const [
SettingsPage(),
IntroPage(),
HomePage(),
IntroPage(),
SettingsPage(),
],
),
)
@ -97,4 +98,32 @@ class _DashboardState extends ConsumerState<Dashboard> {
),
);
}
TextButton bottomButton(
BuildContext context,
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)
.update((state) => buttonIdx);
},
child: Icon(
isSelected ? selectedIcon : icon,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
);
}
}