From c90f75de72d3aa9ca35465566dcd1d521f623c97 Mon Sep 17 00:00:00 2001 From: orz12 Date: Tue, 23 Apr 2024 00:19:02 +0800 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 8285fab60440587dc68d1662b177466d8a533720 Author: orz12 Date: Tue Apr 23 00:16:41 2024 +0800 feat: 自适应导航栏依赖 commit 3af4be16fe5c7c2e97b2b457071f5fe28425905d Merge: 209e1215 ce459701 Author: X64D <152763398+X64D@users.noreply.github.com> Date: Mon Apr 22 15:01:23 2024 +0000 Merge branch 'orz12:main' into main commit 209e121530ed6701c3c729e8d8a5d4b5fc92747b Author: X64D <152763398+X64D@users.noreply.github.com> Date: Mon Apr 8 23:18:43 2024 +0000 feat: 横屏适配 #53 #57 commit 1671f29e9c1d22324ad7d5ededd9e09c84363be4 Author: X64D <152763398+X64D@users.noreply.github.com> Date: Mon Apr 8 23:11:16 2024 +0000 feat: 横屏适配 #53 #57 --- lib/pages/main/view.dart | 41 +++++++++++++++++++++++++++++++++++++++- pubspec.lock | 8 ++++++++ pubspec.yaml | 2 ++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 12c0120ed..863b6775e 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:PiliPalaX/models/common/dynamic_badge_mode.dart'; @@ -30,6 +31,7 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { int? _lastSelectTime; //上次点击时间 Box setting = GStrorage.setting; late bool enableMYBar; + late bool horizontalScreen; @override void initState() { @@ -38,6 +40,7 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { _mainController.pageController = PageController(initialPage: _mainController.selectedIndex); enableMYBar = setting.get(SettingBoxKey.enableMYBar, defaultValue: true); + horizontalScreen = setting.get(SettingBoxKey.horizontalScreen, defaultValue: false); } void setIndex(int value) async { @@ -109,7 +112,43 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { onPopInvoked: (bool didPop) async { _mainController.onBackPressed(context); }, - child: Scaffold( + child: horizontalScreen + ? AdaptiveScaffold( + body: (_) => PageView( + physics: const NeverScrollableScrollPhysics(), + controller: _mainController.pageController, + onPageChanged: (index) { + _mainController.selectedIndex = index; + setState(() {}); + }, + children: _mainController.pages, + ), + destinations: _mainController.navigationBars.map((e) => NavigationDestination( + icon: Badge( + label: _mainController.dynamicBadgeType == + DynamicBadgeMode.number + ? Text(e['count'].toString()) + : null, + padding: const EdgeInsets.fromLTRB(6, 0, 6, 0), + isLabelVisible: + _mainController.dynamicBadgeType != + DynamicBadgeMode.hidden && + e['count'] > 0, + child: e['icon'], + backgroundColor: + Theme.of(context).colorScheme.primary, + textColor: Theme.of(context) + .colorScheme + .onInverseSurface, + ), + selectedIcon: e['selectIcon'], + label: e['label'], + )).toList(), + onSelectedIndexChange: (value) => setIndex(value), + selectedIndex: _mainController.selectedIndex, + useDrawer: false + ) + : Scaffold( extendBody: true, body: PageView( physics: const NeverScrollableScrollPhysics(), diff --git a/pubspec.lock b/pubspec.lock index 41b4354ed..64a3ac3c9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -510,6 +510,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_adaptive_scaffold: + dependency: "direct main" + description: + name: flutter_adaptive_scaffold + sha256: "600bbe237530a249f957f7d0f36273c20bd38d137e28e098c5231c30cadbe927" + url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" + source: hosted + version: "0.1.10+1" flutter_cache_manager: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8fe336d95..200c850d2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,8 @@ dependencies: cupertino_icons: ^1.0.5 # 动态取色 dynamic_color: ^1.6.8 + # Adaptive scaffold + flutter_adaptive_scaffold: ^0.1.10+1 get: ^4.6.5