opt: 首页滑动重载优化,且默认不收起顶栏和底栏

This commit is contained in:
orz12
2024-04-04 10:59:35 +08:00
parent fbce44dfad
commit 0c77439be1
5 changed files with 76 additions and 86 deletions

View File

@@ -35,7 +35,7 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
userLogin.value = userInfo != null; userLogin.value = userInfo != null;
userFace.value = userInfo != null ? userInfo.face : ''; userFace.value = userInfo != null ? userInfo.face : '';
hideSearchBar = hideSearchBar =
setting.get(SettingBoxKey.hideSearchBar, defaultValue: true); setting.get(SettingBoxKey.hideSearchBar, defaultValue: false);
if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) { if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) {
searchDefault(); searchDefault();
} }

View File

@@ -32,7 +32,7 @@ class MainController extends GetxController {
int selectedIndex = 0; int selectedIndex = 0;
Box userInfoCache = GStrorage.userInfo; Box userInfoCache = GStrorage.userInfo;
RxBool userLogin = false.obs; RxBool userLogin = false.obs;
late Rx<DynamicBadgeMode> dynamicBadgeType = DynamicBadgeMode.number.obs; late DynamicBadgeMode dynamicBadgeType;
@override @override
void onInit() { void onInit() {
@@ -40,17 +40,17 @@ class MainController extends GetxController {
if (setting.get(SettingBoxKey.autoUpdate, defaultValue: false)) { if (setting.get(SettingBoxKey.autoUpdate, defaultValue: false)) {
Utils.checkUpdate(); Utils.checkUpdate();
} }
hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: true); hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: false);
int defaultHomePage = int defaultHomePage =
setting.get(SettingBoxKey.defaultHomePage, defaultValue: 0) as int; setting.get(SettingBoxKey.defaultHomePage, defaultValue: 0) as int;
selectedIndex = defaultNavigationBars selectedIndex = defaultNavigationBars
.indexWhere((item) => item['id'] == defaultHomePage); .indexWhere((item) => item['id'] == defaultHomePage);
var userInfo = userInfoCache.get('userInfoCache'); var userInfo = userInfoCache.get('userInfoCache');
userLogin.value = userInfo != null; userLogin.value = userInfo != null;
dynamicBadgeType.value = DynamicBadgeMode.values[setting.get( dynamicBadgeType = DynamicBadgeMode.values[setting.get(
SettingBoxKey.dynamicBadgeMode, SettingBoxKey.dynamicBadgeMode,
defaultValue: DynamicBadgeMode.number.code)]; defaultValue: DynamicBadgeMode.number.code)];
if (dynamicBadgeType.value != DynamicBadgeMode.hidden) { if (dynamicBadgeType != DynamicBadgeMode.hidden) {
getUnreadDynamic(); getUnreadDynamic();
} }
} }

View File

@@ -130,83 +130,73 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
curve: Curves.easeInOutCubicEmphasized, curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500), duration: const Duration(milliseconds: 500),
offset: Offset(0, snapshot.data ? 0 : 1), offset: Offset(0, snapshot.data ? 0 : 1),
child: Obx( child: enableMYBar
() => enableMYBar ? NavigationBar(
? NavigationBar( onDestinationSelected: (value) => setIndex(value),
onDestinationSelected: (value) => setIndex(value), selectedIndex: _mainController.selectedIndex,
selectedIndex: _mainController.selectedIndex, destinations: <Widget>[
destinations: <Widget>[ ..._mainController.navigationBars.map((e) {
..._mainController.navigationBars.map((e) { return NavigationDestination(
return NavigationDestination( icon: Badge(
icon: Obx( label: _mainController.dynamicBadgeType ==
() => Badge( DynamicBadgeMode.number
label: ? Text(e['count'].toString())
_mainController.dynamicBadgeType.value == : null,
DynamicBadgeMode.number padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
? Text(e['count'].toString()) isLabelVisible:
: null, _mainController.dynamicBadgeType !=
padding: DynamicBadgeMode.hidden &&
const EdgeInsets.fromLTRB(6, 0, 6, 0), e['count'] > 0,
isLabelVisible: child: e['icon'],
_mainController.dynamicBadgeType.value != backgroundColor:
DynamicBadgeMode.hidden && Theme.of(context).colorScheme.primary,
e['count'] > 0, textColor: Theme.of(context)
child: e['icon'], .colorScheme
backgroundColor: .onInverseSurface,
Theme.of(context).colorScheme.primary, ),
textColor: Theme.of(context) selectedIcon: e['selectIcon'],
.colorScheme label: e['label'],
.onInverseSurface, );
), }).toList(),
), ],
selectedIcon: e['selectIcon'], )
label: e['label'], : BottomNavigationBar(
); currentIndex: _mainController.selectedIndex,
}).toList(), onTap: (value) => setIndex(value),
], iconSize: 16,
) selectedFontSize: 12,
: BottomNavigationBar( unselectedFontSize: 12,
currentIndex: _mainController.selectedIndex, type: BottomNavigationBarType.fixed,
onTap: (value) => setIndex(value), // selectedItemColor:
iconSize: 16, // Theme.of(context).colorScheme.primary, // 选中项的颜色
selectedFontSize: 12, // unselectedItemColor:
unselectedFontSize: 12, // Theme.of(context).colorScheme.onSurface,
type: BottomNavigationBarType.fixed, items: [
// selectedItemColor: ..._mainController.navigationBars.map((e) {
// Theme.of(context).colorScheme.primary, // 选中项的颜色 return BottomNavigationBarItem(
// unselectedItemColor: icon: Badge(
// Theme.of(context).colorScheme.onSurface, label: _mainController.dynamicBadgeType ==
items: [ DynamicBadgeMode.number
..._mainController.navigationBars.map((e) { ? Text(e['count'].toString())
return BottomNavigationBarItem( : null,
icon: Obx( padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
() => Badge( isLabelVisible:
label: _mainController.dynamicBadgeType !=
_mainController.dynamicBadgeType.value == DynamicBadgeMode.hidden &&
DynamicBadgeMode.number e['count'] > 0,
? Text(e['count'].toString()) child: e['icon'],
: null, backgroundColor:
padding: Theme.of(context).colorScheme.primary,
const EdgeInsets.fromLTRB(6, 0, 6, 0), textColor: Theme.of(context)
isLabelVisible: .colorScheme
_mainController.dynamicBadgeType.value != .onInverseSurface,
DynamicBadgeMode.hidden && ),
e['count'] > 0, activeIcon: e['selectIcon'],
child: e['icon'], label: e['label'],
backgroundColor: );
Theme.of(context).colorScheme.primary, }).toList(),
textColor: Theme.of(context) ],
.colorScheme ),
.onInverseSurface,
),
),
activeIcon: e['selectIcon'],
label: e['label'],
);
}).toList(),
],
),
),
); );
}, },
), ),

View File

@@ -108,9 +108,9 @@ class SettingController extends GetxController {
dynamicBadgeType.value = result; dynamicBadgeType.value = result;
setting.put(SettingBoxKey.dynamicBadgeMode, result.code); setting.put(SettingBoxKey.dynamicBadgeMode, result.code);
MainController mainController = Get.put(MainController()); MainController mainController = Get.put(MainController());
mainController.dynamicBadgeType.value = mainController.dynamicBadgeType =
DynamicBadgeMode.values[result.code]; DynamicBadgeMode.values[result.code];
if (mainController.dynamicBadgeType.value != DynamicBadgeMode.hidden) { if (mainController.dynamicBadgeType != DynamicBadgeMode.hidden) {
mainController.getUnreadDynamic(); mainController.getUnreadDynamic();
} }
SmartDialog.showToast('设置成功'); SmartDialog.showToast('设置成功');

View File

@@ -85,14 +85,14 @@ class _StyleSettingState extends State<StyleSetting> {
title: '首页顶栏收起', title: '首页顶栏收起',
subTitle: '首页列表滑动时,收起顶栏', subTitle: '首页列表滑动时,收起顶栏',
setKey: SettingBoxKey.hideSearchBar, setKey: SettingBoxKey.hideSearchBar,
defaultVal: true, defaultVal: false,
needReboot: true, needReboot: true,
), ),
const SetSwitchItem( const SetSwitchItem(
title: '首页底栏收起', title: '首页底栏收起',
subTitle: '首页列表滑动时,收起底栏', subTitle: '首页列表滑动时,收起底栏',
setKey: SettingBoxKey.hideTabBar, setKey: SettingBoxKey.hideTabBar,
defaultVal: true, defaultVal: false,
needReboot: true, needReboot: true,
), ),
const SetSwitchItem( const SetSwitchItem(