Skip to content

Commit

Permalink
perf: 👌tabbar 切换缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
xuergo committed Apr 21, 2023
1 parent c3b5806 commit ff9d11a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:just_audio_background/just_audio_background.dart';
/// 全局配置
class Global {
/// 用户配置
static UserInfo? profile = UserInfo(token: null);
static UserInfo? profile = null;

/// 是否第一次打开
static bool isFirstOpen = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/Index/Index_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class IndexController extends GetxController {
// 展示欢迎页,倒计时1.5秒之后进入应用
Future startCountdownTimer() async {
await Future.delayed(Duration(milliseconds: 1000), () {
if (Global.isOfflineLogin) {
if (Global.profile != null) {
Get.toNamed(AppRoutes.Tabbar);
} else {
Get.offAllNamed(AppRoutes.Tabbar);
Get.offAllNamed(AppRoutes.Login);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions lib/pages/subscription/subscription_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SubscriptionController extends GetxController {

await initData();
state.loading = false;
update();
super.onInit();
}

Expand Down
3 changes: 3 additions & 0 deletions lib/pages/subscription/subscription_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:all_universe_flutter/common/colors/colors.dart';
import 'package:all_universe_flutter/components/custom_appbar.dart';
import 'package:all_universe_flutter/components/custom_loading.dart';
Expand All @@ -18,6 +20,7 @@ class SubscriptionPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
print("SubscriptionPage");
return GetBuilder<SubscriptionController>(
builder: (_) => state.loading
? CustomLoading()
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/tabbar/tabbar_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:get/get.dart';
class TabbarState {
RxInt selectIndex = 0.obs;

final screens = [
List<Widget> screens = [
HomePage(),
SubscriptionPage(),
PersonalPage(),
Expand Down
9 changes: 7 additions & 2 deletions lib/pages/tabbar/tabbar_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class TabbarPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
print('TabbarPage');
return BaseScaffold(
floatingActionButtonLocation: CustomFloatingActionButtonLocation(
FloatingActionButtonLocation.centerDocked, 0, -(60 / 2).h),
Expand All @@ -38,7 +37,13 @@ class TabbarPage extends StatelessWidget {
return PlayState.playData == null ? SizedBox() : BottomPlayBarPage();
},
),
body: Obx(() => state.screens[state.selectIndex.value]),
body: Obx(
() => IndexedStack(
index: state.selectIndex.value,
children: state.screens,
),
),
// body: Obx(() => state.screens[state.selectIndex.value]),
bottomNavigationBar: Obx(
() => BottomNavigationBar(
type: BottomNavigationBarType.fixed,
Expand Down

0 comments on commit ff9d11a

Please sign in to comment.