From 3afdd9d3f3f8a89cbbfde76af6803cfdf839e084 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Tue, 22 Apr 2025 13:59:08 +0800 Subject: [PATCH] opt: safearea Signed-off-by: bggRGjQaUbCoE --- lib/pages/bangumi/view.dart | 28 +++--- lib/pages/dynamics/view.dart | 95 +++++++++--------- lib/pages/fav/view.dart | 16 ++- lib/pages/history/view.dart | 79 +++++++-------- lib/pages/later/view.dart | 39 ++++---- lib/pages/login/view.dart | 99 ++++++++++--------- lib/pages/member/member_page.dart | 82 ++++++++------- lib/pages/member_search/search_archive.dart | 36 +++---- lib/pages/member_search/search_dynamic.dart | 34 +++---- lib/pages/member_search/view.dart | 32 +++--- lib/pages/search_panel/view.dart | 19 ++-- lib/pages/search_result/view.dart | 104 ++++++++++---------- 12 files changed, 327 insertions(+), 336 deletions(-) diff --git a/lib/pages/bangumi/view.dart b/lib/pages/bangumi/view.dart index 21183be7..099512df 100644 --- a/lib/pages/bangumi/view.dart +++ b/lib/pages/bangumi/view.dart @@ -147,17 +147,17 @@ class _BangumiPageState extends CommonPageState ], ), Expanded( - child: TabBarView( - physics: const NeverScrollableScrollPhysics(), - children: loadingState.response!.map((item) { - if (item.episodes!.isNullOrEmpty) { - return const SizedBox.shrink(); - } - return MediaQuery.removePadding( - context: context, - removeLeft: context.orientation == - Orientation.landscape, - child: ListView.builder( + child: MediaQuery.removePadding( + context: context, + removeLeft: + context.orientation == Orientation.landscape, + child: TabBarView( + physics: const NeverScrollableScrollPhysics(), + children: loadingState.response!.map((item) { + if (item.episodes!.isNullOrEmpty) { + return const SizedBox.shrink(); + } + return ListView.builder( physics: const AlwaysScrollableScrollPhysics(), scrollDirection: Axis.horizontal, @@ -177,9 +177,9 @@ class _BangumiPageState extends CommonPageState ), ); }, - ), - ); - }).toList()), + ); + }).toList()), + ), ), ], ), diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index 6853c596..92a6a8c6 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -134,56 +134,59 @@ class _DynamicsPageState extends State Widget build(BuildContext context) { super.build(context); return Scaffold( - resizeToAvoidBottomInset: false, - appBar: AppBar( - leading: upPanelPosition == UpPanelPosition.rightDrawer - ? _createDynamicBtn(false) - : null, - leadingWidth: 50, - toolbarHeight: 50, - title: SizedBox( - height: 50, - child: TabBar( - controller: _dynamicsController.tabController, - isScrollable: true, - dividerColor: Colors.transparent, - dividerHeight: 0, - tabAlignment: TabAlignment.center, - indicatorColor: Theme.of(context).colorScheme.primary, - labelColor: Theme.of(context).colorScheme.primary, - unselectedLabelColor: Theme.of(context).colorScheme.onSurface, - labelStyle: - TabBarTheme.of(context).labelStyle?.copyWith(fontSize: 13) ?? - const TextStyle(fontSize: 13), - tabs: - DynamicsType.values.map((e) => Tab(text: e.labels)).toList(), - onTap: (index) { - if (!_dynamicsController.tabController.indexIsChanging) { - _dynamicsController.animateToTop(); - } - }, - ), + resizeToAvoidBottomInset: false, + appBar: AppBar( + leading: upPanelPosition == UpPanelPosition.rightDrawer + ? _createDynamicBtn(false) + : null, + leadingWidth: 50, + toolbarHeight: 50, + title: SizedBox( + height: 50, + child: TabBar( + controller: _dynamicsController.tabController, + isScrollable: true, + dividerColor: Colors.transparent, + dividerHeight: 0, + tabAlignment: TabAlignment.center, + indicatorColor: Theme.of(context).colorScheme.primary, + labelColor: Theme.of(context).colorScheme.primary, + unselectedLabelColor: Theme.of(context).colorScheme.onSurface, + labelStyle: + TabBarTheme.of(context).labelStyle?.copyWith(fontSize: 13) ?? + const TextStyle(fontSize: 13), + tabs: DynamicsType.values.map((e) => Tab(text: e.labels)).toList(), + onTap: (index) { + if (!_dynamicsController.tabController.indexIsChanging) { + _dynamicsController.animateToTop(); + } + }, ), - actions: upPanelPosition == UpPanelPosition.rightDrawer - ? null - : [_createDynamicBtn()], ), - drawer: upPanelPosition == UpPanelPosition.leftDrawer - ? SafeArea(child: upPanelPart()) - : null, - drawerEnableOpenDragGesture: true, - endDrawer: upPanelPosition == UpPanelPosition.rightDrawer - ? SafeArea(child: upPanelPart()) - : null, - endDrawerEnableOpenDragGesture: true, - body: Row(children: [ + actions: upPanelPosition == UpPanelPosition.rightDrawer + ? null + : [_createDynamicBtn()], + ), + drawer: upPanelPosition == UpPanelPosition.leftDrawer + ? SafeArea(child: upPanelPart()) + : null, + drawerEnableOpenDragGesture: true, + endDrawer: upPanelPosition == UpPanelPosition.rightDrawer + ? SafeArea(child: upPanelPart()) + : null, + endDrawerEnableOpenDragGesture: true, + body: Row( + children: [ if (upPanelPosition == UpPanelPosition.leftFixed) upPanelPart(), Expanded( - child: tabBarView( - controller: _dynamicsController.tabController, - children: _dynamicsController.tabsPageList, - )), + child: tabBarView( + controller: _dynamicsController.tabController, + children: _dynamicsController.tabsPageList, + ), + ), if (upPanelPosition == UpPanelPosition.rightFixed) upPanelPart(), - ])); + ], + ), + ); } } diff --git a/lib/pages/fav/view.dart b/lib/pages/fav/view.dart index 69abb882..877869b3 100644 --- a/lib/pages/fav/view.dart +++ b/lib/pages/fav/view.dart @@ -134,15 +134,13 @@ class _FavPageState extends State with SingleTickerProviderStateMixin { tabs: _FavType.values.map((item) => Tab(text: item.title)).toList(), ), ), - body: tabBarView( - controller: _tabController, - children: _FavType.values - .map((item) => SafeArea( - top: false, - bottom: false, - child: item.page, - )) - .toList(), + body: SafeArea( + top: false, + bottom: false, + child: tabBarView( + controller: _tabController, + children: _FavType.values.map((item) => item.page).toList(), + ), ), ); } diff --git a/lib/pages/history/view.dart b/lib/pages/history/view.dart index 3c76ad6c..b80097d4 100644 --- a/lib/pages/history/view.dart +++ b/lib/pages/history/view.dart @@ -179,13 +179,13 @@ class _HistoryPageState extends State ), body: Obx( () => _historyController.tabs.isNotEmpty - ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SafeArea( - top: false, - bottom: false, - child: TabBar( + ? SafeArea( + top: false, + bottom: false, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TabBar( controller: _historyController.tabController, onTap: (index) { if (_historyController @@ -206,47 +206,48 @@ class _HistoryPageState extends State ), ], ), - ), - Expanded( - child: Material( - color: Colors.transparent, - child: TabBarView( - physics: enableMultiSelect - ? const NeverScrollableScrollPhysics() - : const CustomTabBarViewScrollPhysics(), - controller: _historyController.tabController, - children: [ - _buildPage, - ..._historyController.tabs.map( - (item) => HistoryPage(type: item.type), - ), - ], + Expanded( + child: Material( + color: Colors.transparent, + child: TabBarView( + physics: enableMultiSelect + ? const NeverScrollableScrollPhysics() + : const CustomTabBarViewScrollPhysics(), + controller: + _historyController.tabController, + children: [ + _buildPage, + ..._historyController.tabs.map( + (item) => HistoryPage(type: item.type), + ), + ], + ), ), ), - ), - ], + ], + ), ) - : _buildPage, + : SafeArea( + top: false, + bottom: false, + child: _buildPage, + ), ), ), ), ); } - Widget get _buildPage => SafeArea( - top: false, - bottom: false, - child: refreshIndicator( - onRefresh: () async { - await _historyController.onRefresh(); - }, - child: CustomScrollView( - physics: const AlwaysScrollableScrollPhysics(), - controller: _historyController.scrollController, - slivers: [ - Obx(() => _buildBody(_historyController.loadingState.value)), - ], - ), + Widget get _buildPage => refreshIndicator( + onRefresh: () async { + await _historyController.onRefresh(); + }, + child: CustomScrollView( + physics: const AlwaysScrollableScrollPhysics(), + controller: _historyController.scrollController, + slivers: [ + Obx(() => _buildBody(_historyController.loadingState.value)), + ], ), ); diff --git a/lib/pages/later/view.dart b/lib/pages/later/view.dart index c8d88bc1..4ee1c4c2 100644 --- a/lib/pages/later/view.dart +++ b/lib/pages/later/view.dart @@ -86,12 +86,12 @@ class _LaterPageState extends State ) : const SizedBox(), ), - body: Column( - children: [ - SafeArea( - top: false, - bottom: false, - child: TabBar( + body: SafeArea( + top: false, + bottom: false, + child: Column( + children: [ + TabBar( isScrollable: true, controller: _tabController, tabAlignment: TabAlignment.start, @@ -110,23 +110,18 @@ class _LaterPageState extends State } }, ), - ), - Expanded( - child: TabBarView( - physics: _baseCtr.enableMultiSelect.value - ? const NeverScrollableScrollPhysics() - : const CustomTabBarViewScrollPhysics(), - controller: _tabController, - children: LaterViewType.values - .map((item) => SafeArea( - top: false, - bottom: false, - child: item.page, - )) - .toList(), + Expanded( + child: TabBarView( + physics: _baseCtr.enableMultiSelect.value + ? const NeverScrollableScrollPhysics() + : const CustomTabBarViewScrollPhysics(), + controller: _tabController, + children: + LaterViewType.values.map((item) => item.page).toList(), + ), ), - ), - ], + ], + ), ), ), ), diff --git a/lib/pages/login/view.dart b/lib/pages/login/view.dart index 2659914d..b9878d37 100644 --- a/lib/pages/login/view.dart +++ b/lib/pages/login/view.dart @@ -471,46 +471,54 @@ class _LoginPageState extends State { return Scaffold( appBar: AppBar( leading: IconButton( - tooltip: '关闭', - icon: const Icon(Icons.close_outlined), - onPressed: Get.back), - title: Row(children: [ - const Text('登录'), - if (orientation == Orientation.landscape) ...[ - const Spacer(), - Flexible( + tooltip: '关闭', + icon: const Icon(Icons.close_outlined), + onPressed: Get.back, + ), + title: Row( + children: [ + const Text('登录'), + if (orientation == Orientation.landscape) ...[ + const Spacer(flex: 3), + Flexible( + flex: 5, child: TabBar( - dividerHeight: 0, - tabs: const [ - Tab( - child: Row( - mainAxisSize: MainAxisSize.min, - children: [Icon(Icons.password), Text(' 密码')], - ), + dividerHeight: 0, + tabs: const [ + Tab( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [Icon(Icons.password), Text(' 密码')], + ), + ), + Tab( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [Icon(Icons.sms_outlined), Text(' 短信')], + ), + ), + Tab( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [Icon(Icons.qr_code), Text(' 扫码')], + ), + ), + Tab( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.cookie_outlined), + Text(' Cookie') + ], + ), + ), + ], + controller: _loginPageCtr.tabController, ), - Tab( - child: Row( - mainAxisSize: MainAxisSize.min, - children: [Icon(Icons.sms_outlined), Text(' 短信')], - ), - ), - Tab( - child: Row( - mainAxisSize: MainAxisSize.min, - children: [Icon(Icons.qr_code), Text(' 扫码')], - ), - ), - Tab( - child: Row( - mainAxisSize: MainAxisSize.min, - children: [Icon(Icons.cookie_outlined), Text(' Cookie')], - ), - ), - ], - controller: _loginPageCtr.tabController, - )) - ] - ]), + ) + ], + ], + ), bottom: orientation == Orientation.portrait ? TabBar( tabs: const [ @@ -548,12 +556,13 @@ class _LoginPageState extends State { Widget tabViewOuter(child) { return SingleChildScrollView( - child: Align( - alignment: Alignment.topCenter, - child: SizedBox( - height: 500, - width: 600, - child: child, - ))); + child: Align( + alignment: Alignment.topCenter, + child: ConstrainedBox( + constraints: BoxConstraints(maxWidth: 600), + child: child, + ), + ), + ); } } diff --git a/lib/pages/member/member_page.dart b/lib/pages/member/member_page.dart index fa6b2fd9..89b39625 100644 --- a/lib/pages/member/member_page.dart +++ b/lib/pages/member/member_page.dart @@ -173,12 +173,16 @@ class _MemberPageNewState extends State { ]; }, body: _userController.tab2?.isNotEmpty == true - ? Column( - children: [ - if ((_userController.tab2?.length ?? 0) > 1) - _buildTab, - Expanded(child: _buildBody), - ], + ? SafeArea( + top: false, + bottom: false, + child: Column( + children: [ + if ((_userController.tab2?.length ?? 0) > 1) + _buildTab, + Expanded(child: _buildBody), + ], + ), ) : Center(child: const Text('EMPTY')), ); @@ -193,49 +197,41 @@ class _MemberPageNewState extends State { Widget get _buildTab => Material( color: Theme.of(context).colorScheme.surface, - child: SafeArea( - top: false, - bottom: false, - child: TabBar( - controller: _userController.tabController, - tabs: _userController.tabs, - onTap: (value) { - if (_userController.tabController?.indexIsChanging == false) { - _key.currentState?.outerController.animToTop(); - } - }, - ), + child: TabBar( + controller: _userController.tabController, + tabs: _userController.tabs, + onTap: (value) { + if (_userController.tabController?.indexIsChanging == false) { + _key.currentState?.outerController.animToTop(); + } + }, ), ); - Widget get _buildBody => SafeArea( - top: false, - bottom: false, - child: tabBarView( - controller: _userController.tabController, - children: _userController.tab2!.map((item) { - return switch (item.param!) { - 'home' => MemberHome(heroTag: _heroTag), - 'dynamic' => MemberDynamicsPage(mid: _mid), - 'contribute' => Obx( - () => MemberContribute( - heroTag: _heroTag, - initialIndex: _userController.contributeInitialIndex.value, - mid: _mid, - ), - ), - 'bangumi' => MemberBangumi( + Widget get _buildBody => tabBarView( + controller: _userController.tabController, + children: _userController.tab2!.map((item) { + return switch (item.param!) { + 'home' => MemberHome(heroTag: _heroTag), + 'dynamic' => MemberDynamicsPage(mid: _mid), + 'contribute' => Obx( + () => MemberContribute( heroTag: _heroTag, + initialIndex: _userController.contributeInitialIndex.value, mid: _mid, ), - 'favorite' => MemberFavorite( - heroTag: _heroTag, - mid: _mid, - ), - _ => Center(child: Text(item.title ?? '')), - }; - }).toList(), - ), + ), + 'bangumi' => MemberBangumi( + heroTag: _heroTag, + mid: _mid, + ), + 'favorite' => MemberFavorite( + heroTag: _heroTag, + mid: _mid, + ), + _ => Center(child: Text(item.title ?? '')), + }; + }).toList(), ); Widget _buildAppBar({bool isV = true}) { diff --git a/lib/pages/member_search/search_archive.dart b/lib/pages/member_search/search_archive.dart index 2eb29df7..39067b1a 100644 --- a/lib/pages/member_search/search_archive.dart +++ b/lib/pages/member_search/search_archive.dart @@ -28,26 +28,22 @@ class _SearchArchiveState extends State @override Widget build(BuildContext context) { super.build(context); - return SafeArea( - top: false, - bottom: false, - child: refreshIndicator( - onRefresh: () async { - await widget.ctr.refreshArchive(); - }, - child: CustomScrollView( - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - SliverPadding( - padding: EdgeInsets.only( - top: StyleString.safeSpace - 5, - bottom: MediaQuery.paddingOf(context).bottom + 80, - ), - sliver: - Obx(() => _buildBody(context, widget.ctr.archiveState.value)), - ) - ], - ), + return refreshIndicator( + onRefresh: () async { + await widget.ctr.refreshArchive(); + }, + child: CustomScrollView( + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + SliverPadding( + padding: EdgeInsets.only( + top: StyleString.safeSpace - 5, + bottom: MediaQuery.paddingOf(context).bottom + 80, + ), + sliver: + Obx(() => _buildBody(context, widget.ctr.archiveState.value)), + ) + ], ), ); } diff --git a/lib/pages/member_search/search_dynamic.dart b/lib/pages/member_search/search_dynamic.dart index b0893748..fedf9ca3 100644 --- a/lib/pages/member_search/search_dynamic.dart +++ b/lib/pages/member_search/search_dynamic.dart @@ -30,25 +30,21 @@ class _SearchDynamicState extends State @override Widget build(BuildContext context) { super.build(context); - return SafeArea( - top: false, - bottom: false, - child: refreshIndicator( - onRefresh: () async { - await widget.ctr.refreshDynamic(); - }, - child: CustomScrollView( - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - SliverPadding( - padding: EdgeInsets.only( - bottom: MediaQuery.paddingOf(context).bottom + 80, - ), - sliver: - Obx(() => _buildBody(context, widget.ctr.dynamicState.value)), - ) - ], - ), + return refreshIndicator( + onRefresh: () async { + await widget.ctr.refreshDynamic(); + }, + child: CustomScrollView( + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + SliverPadding( + padding: EdgeInsets.only( + bottom: MediaQuery.paddingOf(context).bottom + 80, + ), + sliver: + Obx(() => _buildBody(context, widget.ctr.dynamicState.value)), + ) + ], ), ); } diff --git a/lib/pages/member_search/view.dart b/lib/pages/member_search/view.dart index 6242f69e..79241008 100644 --- a/lib/pages/member_search/view.dart +++ b/lib/pages/member_search/view.dart @@ -53,12 +53,12 @@ class _MemberSearchPageState extends State { ), body: Obx( () => _memberSearchCtr.hasData.value - ? Column( - children: [ - SafeArea( - top: false, - bottom: false, - child: TabBar( + ? SafeArea( + top: false, + bottom: false, + child: Column( + children: [ + TabBar( controller: _memberSearchCtr.tabController, tabs: [ Obx( @@ -75,17 +75,17 @@ class _MemberSearchPageState extends State { ), ], ), - ), - Expanded( - child: tabBarView( - controller: _memberSearchCtr.tabController, - children: [ - SearchArchive(ctr: _memberSearchCtr), - SearchDynamic(ctr: _memberSearchCtr), - ], + Expanded( + child: tabBarView( + controller: _memberSearchCtr.tabController, + children: [ + SearchArchive(ctr: _memberSearchCtr), + SearchDynamic(ctr: _memberSearchCtr), + ], + ), ), - ), - ], + ], + ), ) : FractionallySizedBox( heightFactor: 0.5, diff --git a/lib/pages/search_panel/view.dart b/lib/pages/search_panel/view.dart index c9260b76..e7163010 100644 --- a/lib/pages/search_panel/view.dart +++ b/lib/pages/search_panel/view.dart @@ -45,17 +45,14 @@ abstract class CommonSearchPanelState< onRefresh: () async { await controller.onRefresh(); }, - child: SafeArea( - bottom: false, - child: CustomScrollView( - controller: controller.scrollController, - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - if (widget.hasHeader) - Obx(() => buildHeader(controller.loadingState.value)), - Obx(() => _buildBody(controller.loadingState.value)), - ], - ), + child: CustomScrollView( + controller: controller.scrollController, + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + if (widget.hasHeader) + Obx(() => buildHeader(controller.loadingState.value)), + Obx(() => _buildBody(controller.loadingState.value)), + ], ), ); } diff --git a/lib/pages/search_result/view.dart b/lib/pages/search_result/view.dart index 41302000..d0fbeb86 100644 --- a/lib/pages/search_result/view.dart +++ b/lib/pages/search_result/view.dart @@ -92,12 +92,12 @@ class _SearchResultPageState extends State ), ), ), - body: Column( - children: [ - SafeArea( - top: false, - bottom: false, - child: SizedBox( + body: SafeArea( + top: false, + bottom: false, + child: Column( + children: [ + SizedBox( width: double.infinity, child: TabBar( overlayColor: WidgetStateProperty.all(Colors.transparent), @@ -145,54 +145,54 @@ class _SearchResultPageState extends State }, ), ), - ), - Expanded( - child: Material( - color: Colors.transparent, - child: tabBarView( - controller: _tabController, - children: SearchType.values - .map( - (item) => switch (item) { - // SearchType.all => SearchAllPanel( - // tag: _tag, - // searchType: item, - // keyword: _searchResultController.keyword, - // ), - SearchType.video => SearchVideoPanel( - tag: _tag, - searchType: item, - keyword: _searchResultController.keyword, - ), - SearchType.media_bangumi || - SearchType.media_ft => - SearchPgcPanel( - tag: _tag, - searchType: item, - keyword: _searchResultController.keyword, - ), - SearchType.live_room => SearchLivePanel( - tag: _tag, - searchType: item, - keyword: _searchResultController.keyword, - ), - SearchType.bili_user => SearchUserPanel( - tag: _tag, - searchType: item, - keyword: _searchResultController.keyword, - ), - SearchType.article => SearchArticlePanel( - tag: _tag, - searchType: item, - keyword: _searchResultController.keyword, - ), - }, - ) - .toList(), + Expanded( + child: Material( + color: Colors.transparent, + child: tabBarView( + controller: _tabController, + children: SearchType.values + .map( + (item) => switch (item) { + // SearchType.all => SearchAllPanel( + // tag: _tag, + // searchType: item, + // keyword: _searchResultController.keyword, + // ), + SearchType.video => SearchVideoPanel( + tag: _tag, + searchType: item, + keyword: _searchResultController.keyword, + ), + SearchType.media_bangumi || + SearchType.media_ft => + SearchPgcPanel( + tag: _tag, + searchType: item, + keyword: _searchResultController.keyword, + ), + SearchType.live_room => SearchLivePanel( + tag: _tag, + searchType: item, + keyword: _searchResultController.keyword, + ), + SearchType.bili_user => SearchUserPanel( + tag: _tag, + searchType: item, + keyword: _searchResultController.keyword, + ), + SearchType.article => SearchArticlePanel( + tag: _tag, + searchType: item, + keyword: _searchResultController.keyword, + ), + }, + ) + .toList(), + ), ), ), - ), - ], + ], + ), ), ); }