Skip to content

Commit

Permalink
Fixes PageState not loading using the correct index after closing the…
Browse files Browse the repository at this point in the history
… app. (#505)

* fix: pageview loading incorrect page on applaunch, removes animation for navigating the 3 main pages

* removes redundant method
  • Loading branch information
Wreck-X authored Mar 11, 2024
1 parent 0e30813 commit 415bc9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class BottomNavigationBarController extends GetxController
with WidgetsBindingObserver {
RxInt activeTabIndex = 0.obs;
RxBool isTimerRunning = false.obs;
RxBool hasloaded = false.obs;

final _secureStorageProvider = SecureStorageProvider();

Expand All @@ -25,7 +26,7 @@ class BottomNavigationBarController extends GetxController
void onInit() {
super.onInit();
WidgetsBinding.instance.addObserver(this);
_loadSavedState();
loadSavedState();
}

@override
Expand All @@ -44,8 +45,10 @@ class BottomNavigationBarController extends GetxController
}
}

void _loadSavedState() async {
activeTabIndex.value = await _secureStorageProvider.readTabIndex();
Future<void> loadSavedState() async {
int value = await _secureStorageProvider.readTabIndex();
activeTabIndex.value = value;
hasloaded.value = true;
}

void _saveState() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,40 @@ import 'package:ultimate_alarm_clock/app/utils/constants.dart';
import 'package:ultimate_alarm_clock/app/utils/utils.dart';

class BottomNavigationBarView extends GetView<BottomNavigationBarController> {
final PageController pageController = PageController();
PageController pageController = PageController();
final ThemeController themeController = Get.find<ThemeController>();

BottomNavigationBarView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
controller: pageController,
children: controller.pages,
onPageChanged: (index) {
controller.changeTab(index);
},
),
body: Obx(() {
return FutureBuilder(
future: controller.loadSavedState(),
builder: (context, snapshot) {
if (controller.hasloaded.value != false) {
pageController =
PageController(initialPage: controller.activeTabIndex.value);
return PageView(
controller: pageController,
children: controller.pages,
onPageChanged: (index) {
controller.changeTab(index);
},
);
} else {
return const Center(
child: CircularProgressIndicator.adaptive(
backgroundColor: Colors.transparent,
valueColor: AlwaysStoppedAnimation(
kprimaryColor,
),
),
);
}
},
);
}),
bottomNavigationBar: Obx(
() => BottomNavigationBar(
useLegacyColorScheme: false,
Expand All @@ -40,10 +60,8 @@ class BottomNavigationBarView extends GetView<BottomNavigationBarController> {
onTap: (index) {
Utils.hapticFeedback();
controller.changeTab(index);
pageController.animateToPage(
pageController.jumpToPage(
index,
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
},
currentIndex: controller.activeTabIndex.value,
Expand Down
3 changes: 1 addition & 2 deletions lib/app/modules/home/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ class HomeView extends GetView<HomeController> {
children: [
// All alarm select button
ToggleButton(
controller:
controller:
controller,
isSelected: controller
.isAllAlarmsSelected,
Expand Down Expand Up @@ -758,7 +758,6 @@ class HomeView extends GetView<HomeController> {
);
}
final AlarmModel alarm = alarms[index];

final repeatDays =
Utils.getRepeatDays(alarm.days);
// Main card
Expand Down

0 comments on commit 415bc9f

Please sign in to comment.