Skip to content

Commit

Permalink
[FIX] Bug with bottom nav bar index
Browse files Browse the repository at this point in the history
  • Loading branch information
31Nathan committed Nov 21, 2024
1 parent 07c3ebe commit 016ce7d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 52 deletions.
28 changes: 12 additions & 16 deletions Application/mobile/app_code/lib/components/bottomnavbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,24 @@ class BottomNavBar extends StatelessWidget {
label: AppLocalizations.of(context)!.search,
),
];
if (userInformation != null) {
items.add(
BottomNavigationBarItem(
icon: const Icon(Icons.shopping_basket),
label: AppLocalizations.of(context)!.myRents,
),
);
}
items.add(
BottomNavigationBarItem(
icon: const Icon(Icons.shopping_basket),
label: AppLocalizations.of(context)!.myRents,
),
);
items.add(
BottomNavigationBarItem(
icon: const Icon(Icons.map),
label: AppLocalizations.of(context)!.map,
),
);
if (userInformation != null) {
items.add(
BottomNavigationBarItem(
icon: const Icon(Icons.favorite),
label: AppLocalizations.of(context)!.favorites,
),
);
}
items.add(
BottomNavigationBarItem(
icon: const Icon(Icons.favorite),
label: AppLocalizations.of(context)!.favorites,
),
);
if (userInformation == null) {
items.add(BottomNavigationBarItem(
icon: const Icon(Icons.settings),
Expand Down
56 changes: 22 additions & 34 deletions Application/mobile/app_code/lib/pages/home/home_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:risu/pages/rent/rentals/rentals_page.dart';
import 'package:risu/pages/reset_password/reset_password_page.dart';
import 'package:risu/pages/settings/settings_page.dart';
import 'package:risu/pages/signup/signup_page.dart';
import 'package:risu/utils/check_signin.dart';
import 'package:risu/utils/errors.dart';
import 'package:risu/utils/providers/theme.dart';

Expand All @@ -31,7 +32,7 @@ import 'home_page.dart';
/// This class is the state of the HomePage class
/// It contains the logic of the HomePage class
class HomePageState extends State<HomePage> {
int _currentIndex = 1;
int _currentIndex = 2;
late List<Widget> _pages;
bool didAskForProfile = false;
int? containerId;
Expand All @@ -55,38 +56,20 @@ class HomePageState extends State<HomePage> {
configProfile(context);
}
});
if (userInformation == null) {
_pages = [
ContainerPage(
onDirectionClicked: (id) {
setState(() {
_currentIndex = 1;
containerId = id;
});
},
),
const MapPage(),
const ProfilePage(),
];
} else {
setState(() {
_currentIndex = 2;
});
_pages = [
ContainerPage(
onDirectionClicked: (id) {
setState(() {
_currentIndex = 2;
containerId = id;
});
},
),
const RentalPage(appbar: false),
const MapPage(),
const FavoritePage(appbar: false),
const ProfilePage(),
];
}
_pages = [
ContainerPage(
onDirectionClicked: (id) {
setState(() {
_currentIndex = 2;
containerId = id;
});
},
),
const RentalPage(appbar: false),
const MapPage(),
const FavoritePage(appbar: false),
const ProfilePage(),
];
}

Future<void> redirectFromUri(Uri uri, String link) async {
Expand Down Expand Up @@ -279,13 +262,18 @@ class HomePageState extends State<HomePage> {
currentIndex: _currentIndex,
onTap: (index) async {
setState(() {
if ((index == 2 || index == 4) && userInformation == null) {
if (index == 4 && userInformation == null) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const SettingsPage();
}),
);
} else if ((index == 1 || index == 3) &&
userInformation == null) {
if (checkSignin(context)) {
_currentIndex = index;
}
} else {
_currentIndex = index;
}
Expand Down
4 changes: 2 additions & 2 deletions Application/mobile/app_code/test/bottomnavbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void main() {
// Verify that the initial currentIndex is 0.
expect(currentIndex, 0);

// Tap the second item (index 1) in the BottomNavigationBar.
// Tap the second item (index 2) in the BottomNavigationBar.
await tester.tap(find.byType(BottomNavBar));
await tester.pumpAndSettle();

// Verify that the currentIndex has changed to 1.
expect(currentIndex, 1);
expect(currentIndex, 2);
});
}

0 comments on commit 016ce7d

Please sign in to comment.