completed first web iteration
This commit is contained in:
209
lib/navbar.dart
Normal file
209
lib/navbar.dart
Normal file
@@ -0,0 +1,209 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'models/responsive_policy.dart';
|
||||
|
||||
class ScaffoldWithNavBar extends StatefulWidget {
|
||||
const ScaffoldWithNavBar({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<ScaffoldWithNavBar> createState() => _ScaffoldWithNavBarState();
|
||||
}
|
||||
|
||||
class _ScaffoldWithNavBarState extends State<ScaffoldWithNavBar> {
|
||||
bool _isLoggedIn = false;
|
||||
late String initials;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
init();
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
|
||||
if (prefs.getString("token") != null) {
|
||||
setState(() {
|
||||
_isLoggedIn = true;
|
||||
initials = prefs.getString("initials")!;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (constraints.maxWidth > ResponsivePolicy.md) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Row(
|
||||
children: [
|
||||
NavigationRail(
|
||||
extended: true,
|
||||
leading: Padding(
|
||||
padding: const EdgeInsets.only(top: 20.0, bottom: 10),
|
||||
child: Image(
|
||||
image: AssetImage('assets/velocity.png'),
|
||||
width: 150
|
||||
),
|
||||
),
|
||||
trailing: _buildLogin(context),
|
||||
labelType: NavigationRailLabelType.none,
|
||||
indicatorColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary.withAlpha(30),
|
||||
onDestinationSelected: (index) {
|
||||
_handleTap(index, context);
|
||||
},
|
||||
selectedIndex: _calculateSelectedIndex(context),
|
||||
destinations: _buildNavigationRailDestinations(),
|
||||
),
|
||||
VerticalDivider(
|
||||
thickness: 1,
|
||||
width: 1,
|
||||
color: Theme.of(context).colorScheme.primary.withAlpha(30),
|
||||
),
|
||||
Expanded(child: widget.child),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
body: widget.child,
|
||||
bottomNavigationBar: NavigationBar(
|
||||
indicatorColor: Theme.of(context).colorScheme.primary.withAlpha(30),
|
||||
onDestinationSelected: (index) {
|
||||
_handleTap(index, context);
|
||||
},
|
||||
selectedIndex: _calculateSelectedIndex(context),
|
||||
destinations: _buildNavigationDestinations(),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
List<NavigationRailDestination> _buildNavigationRailDestinations() {
|
||||
List<NavigationRailDestination> destinations = [];
|
||||
for (var destination in _buildDestinationData()) {
|
||||
destinations.add(
|
||||
NavigationRailDestination(
|
||||
icon: destination["icon"] as Widget,
|
||||
selectedIcon: destination["selectedIcon"] as Widget,
|
||||
label: Text(destination["label"], style: TextStyle(fontSize: 16)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return destinations;
|
||||
}
|
||||
|
||||
List<NavigationDestination> _buildNavigationDestinations() {
|
||||
List<NavigationDestination> destinations = [];
|
||||
for (var destination in _buildDestinationData()) {
|
||||
destinations.add(
|
||||
NavigationDestination(
|
||||
icon: destination["icon"] as Widget,
|
||||
selectedIcon: destination["selectedIcon"] as Widget,
|
||||
label: destination["label"] as String,
|
||||
),
|
||||
);
|
||||
}
|
||||
return destinations;
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> _buildDestinationData() {
|
||||
return [
|
||||
{
|
||||
"icon": Icon(Icons.home_outlined),
|
||||
"selectedIcon": Icon(Icons.home),
|
||||
"label": 'Home',
|
||||
},
|
||||
{
|
||||
"icon": Icon(Icons.history_outlined),
|
||||
"selectedIcon": Icon(Icons.history),
|
||||
"label": 'History',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildLogin(BuildContext context) {
|
||||
if(_isLoggedIn) {
|
||||
return SizedBox();
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 220,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black87.withAlpha(20)),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
spacing: 10,
|
||||
children: [
|
||||
Text(
|
||||
'Register or Login for more features',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
context.push('/onboarding/landing');
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text('Get Started', style: TextStyle(fontSize: 14)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleTap(int index, BuildContext context) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
context.go('/home');
|
||||
break;
|
||||
// case 1:
|
||||
// context.go('/recipients');
|
||||
// break;
|
||||
case 1:
|
||||
context.go('/history');
|
||||
break;
|
||||
// case 2:
|
||||
// context.go('/profile');
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
int _calculateSelectedIndex(BuildContext context) {
|
||||
final String location = GoRouterState.of(context).uri.path;
|
||||
// if (location.startsWith('/recipients')) return 1;
|
||||
if (location.startsWith('/history')) return 1;
|
||||
// if (location.startsWith('/profile')) return 2;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user