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,61 +21,62 @@ 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,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
isSelected: railIdx == 0,
onPressed: () {
ref ref
.read(navRailIndexStateProvider.notifier) .read(navRailIndexStateProvider.notifier)
.update((state) => index); .update((state) => 0);
});
}, },
labelType: NavigationRailLabelType.all, icon: const Icon(Icons.auto_awesome_mosaic_outlined),
leading: SizedBox(height: kIsMacOS ? 24.0 : 8.0), selectedIcon: const Icon(Icons.auto_awesome_mosaic),
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,
), ),
), Text(
), 'Requests',
), style: Theme.of(context).textTheme.labelSmall,
),
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'),
), ),
], ],
), ),
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( VerticalDivider(
thickness: 1, thickness: 1,
width: 1, width: 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,
),
);
}
} }