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:apidash/consts.dart';
import 'package:flutter_riverpod/flutter_riverpod.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 activeIdStateProvider = StateProvider<String?>((ref) => null);
final activeIdEditStateProvider = StateProvider<String?>((ref) => null); final activeIdEditStateProvider = StateProvider<String?>((ref) => null);
final sentRequestIdStateProvider = StateProvider<String?>((ref) => null); final sentRequestIdStateProvider = StateProvider<String?>((ref) => null);
final codePaneVisibleStateProvider = StateProvider<bool>((ref) => false); final codePaneVisibleStateProvider = StateProvider<bool>((ref) => false);
final saveDataStateProvider = StateProvider<bool>((ref) => false); final saveDataStateProvider = StateProvider<bool>((ref) => false);
final clearDataStateProvider = 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,60 +21,61 @@ class _DashboardState extends ConsumerState<Dashboard> {
body: SafeArea( body: SafeArea(
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
NavigationRail( Column(
selectedIndex: railIdx, children: [
groupAlignment: -1.0, SizedBox(
onDestinationSelected: (int index) { height: kIsMacOS ? 32.0 : 16.0,
setState(() { width: 64,
ref ),
.read(navRailIndexStateProvider.notifier) Column(
.update((state) => index); mainAxisSize: MainAxisSize.min,
}); children: [
}, IconButton(
labelType: NavigationRailLabelType.all, isSelected: railIdx == 0,
leading: SizedBox(height: kIsMacOS ? 24.0 : 8.0), onPressed: () {
trailing: Expanded( ref
child: Align( .read(navRailIndexStateProvider.notifier)
alignment: Alignment.bottomCenter, .update((state) => 0);
child: Padding( },
padding: const EdgeInsets.only(bottom: 16.0), icon: const Icon(Icons.auto_awesome_mosaic_outlined),
child: TextButton( selectedIcon: const Icon(Icons.auto_awesome_mosaic),
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,
),
), ),
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'),
),
], ],
// 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( VerticalDivider(
thickness: 1, thickness: 1,
@ -84,11 +85,11 @@ class _DashboardState extends ConsumerState<Dashboard> {
Expanded( Expanded(
child: IndexedStack( child: IndexedStack(
alignment: AlignmentDirectional.topCenter, alignment: AlignmentDirectional.topCenter,
index: railIdx == null ? 0 : railIdx + 1, index: railIdx,
children: const [ children: const [
SettingsPage(),
IntroPage(),
HomePage(), 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,
),
);
}
} }