From aa4ffbe4fbcdc34bad1fe559f2f597e3d7e66bd2 Mon Sep 17 00:00:00 2001 From: chen08209 Date: Sun, 14 Jul 2024 01:37:44 +0800 Subject: [PATCH] Fix fab issues --- core/common.go | 4 +- lib/fragments/access.dart | 326 +++++++++++++-------------- lib/fragments/profiles/profiles.dart | 149 ++++++------ lib/widgets/scaffold.dart | 10 - pubspec.yaml | 2 +- 5 files changed, 241 insertions(+), 250 deletions(-) diff --git a/core/common.go b/core/common.go index cedb251..b891bd2 100644 --- a/core/common.go +++ b/core/common.go @@ -325,8 +325,8 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi //targetConfig.GeodataMode = false targetConfig.IPv6 = patchConfig.IPv6 targetConfig.LogLevel = patchConfig.LogLevel - targetConfig.Port = 0 - targetConfig.SocksPort = 0 + //targetConfig.Port = 0 + //targetConfig.SocksPort = 0 targetConfig.MixedPort = patchConfig.MixedPort targetConfig.FindProcessMode = patchConfig.FindProcessMode targetConfig.AllowLan = patchConfig.AllowLan diff --git a/lib/fragments/access.dart b/lib/fragments/access.dart index 77afaca..1f402a1 100644 --- a/lib/fragments/access.dart +++ b/lib/fragments/access.dart @@ -35,7 +35,6 @@ class _AccessFragmentState extends State { }); } - @override void dispose() { super.dispose(); @@ -112,55 +111,48 @@ class _AccessFragmentState extends State { ); } - _buildSelectedAllButton({ + Widget _buildSelectedAllButton({ required bool isAccessControl, required bool isSelectedAll, required List allValueList, }) { - WidgetsBinding.instance.addPostFrameCallback((_) { - final tooltip = isSelectedAll - ? appLocalizations.cancelSelectAll - : appLocalizations.selectAll; - final commonScaffoldState = - context.findAncestorStateOfType(); - commonScaffoldState?.floatingActionButton = DisabledMask( - status: !isAccessControl, - child: AbsorbPointer( - absorbing: !isAccessControl, - child: FloatingActionButton ( - tooltip: tooltip, - onPressed: () { - final config = globalState.appController.config; - final isAccept = - config.accessControl.mode == AccessControlMode.acceptSelected; + final tooltip = isSelectedAll + ? appLocalizations.cancelSelectAll + : appLocalizations.selectAll; + return AbsorbPointer( + absorbing: !isAccessControl, + child: FloatingActionButton( + tooltip: tooltip, + onPressed: () { + final config = globalState.appController.config; + final isAccept = + config.accessControl.mode == AccessControlMode.acceptSelected; - if (isSelectedAll) { - config.accessControl = switch (isAccept) { - true => config.accessControl.copyWith( - acceptList: [], - ), - false => config.accessControl.copyWith( - rejectList: [], - ), - }; - } else { - config.accessControl = switch (isAccept) { - true => config.accessControl.copyWith( - acceptList: allValueList, - ), - false => config.accessControl.copyWith( - rejectList: allValueList, - ), - }; - } - }, - child: isSelectedAll - ? const Icon(Icons.deselect) - : const Icon(Icons.select_all), - ), - ), - ); - }); + if (isSelectedAll) { + config.accessControl = switch (isAccept) { + true => config.accessControl.copyWith( + acceptList: [], + ), + false => config.accessControl.copyWith( + rejectList: [], + ), + }; + } else { + config.accessControl = switch (isAccept) { + true => config.accessControl.copyWith( + acceptList: allValueList, + ), + false => config.accessControl.copyWith( + rejectList: allValueList, + ), + }; + } + }, + child: isSelectedAll + ? const Icon(Icons.deselect) + : const Icon(Icons.select_all), + ), + ); } Widget _buildPackageList() { @@ -213,137 +205,141 @@ class _AccessFragmentState extends State { accessControlMode == AccessControlMode.acceptSelected ? appLocalizations.accessControlAllowDesc : appLocalizations.accessControlNotAllowDesc; - _buildSelectedAllButton( - isAccessControl: isAccessControl, - isSelectedAll: valueList.length == packageNameList.length, - allValueList: packageNameList, - ); return DisabledMask( status: !isAccessControl, - child: Column( - children: [ - AbsorbPointer( - absorbing: !isAccessControl, - child: Padding( - padding: const EdgeInsets.only( - top: 4, - bottom: 4, - left: 16, - right: 8, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: IntrinsicHeight( - child: Column( - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Row( - children: [ - Flexible( - child: Text( - appLocalizations.selected, - style: Theme.of(context) - .textTheme - .labelLarge - ?.copyWith( - color: Theme.of(context) - .colorScheme - .primary, - ), + child: FloatLayout( + floatingWidget: FloatWrapper( + child: _buildSelectedAllButton( + isAccessControl: isAccessControl, + isSelectedAll: valueList.length == packageNameList.length, + allValueList: packageNameList, + ), + ), + child: Column( + children: [ + AbsorbPointer( + absorbing: !isAccessControl, + child: Padding( + padding: const EdgeInsets.only( + top: 4, + bottom: 4, + left: 16, + right: 8, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + child: IntrinsicHeight( + child: Column( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Row( + children: [ + Flexible( + child: Text( + appLocalizations.selected, + style: Theme.of(context) + .textTheme + .labelLarge + ?.copyWith( + color: Theme.of(context) + .colorScheme + .primary, + ), + ), ), - ), - const Flexible( - child: SizedBox( - width: 8, + const Flexible( + child: SizedBox( + width: 8, + ), ), - ), - Flexible( - child: Text( - "${valueList.length}", - style: Theme.of(context) - .textTheme - .labelLarge - ?.copyWith( - color: Theme.of(context) - .colorScheme - .primary, - ), + Flexible( + child: Text( + "${valueList.length}", + style: Theme.of(context) + .textTheme + .labelLarge + ?.copyWith( + color: Theme.of(context) + .colorScheme + .primary, + ), + ), ), - ), - ], + ], + ), ), - ), - Flexible( - child: Text(describe), - ) - ], + Flexible( + child: Text(describe), + ) + ], + ), ), ), - ), - Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Flexible( - child: _buildSearchButton(currentPackages)), - Flexible(child: _buildFilterSystemAppButton()), - Flexible(child: _buildAppProxyModePopup()), - ], - ), - ], + Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Flexible( + child: _buildSearchButton(currentPackages)), + Flexible(child: _buildFilterSystemAppButton()), + Flexible(child: _buildAppProxyModePopup()), + ], + ), + ], + ), ), ), - ), - Expanded( - flex: 1, - child: FadeBox( - key: const Key("fade_box"), - child: currentPackages.isEmpty - ? const Center( - child: CircularProgressIndicator(), - ) - : ListView.builder( - itemCount: currentPackages.length, - itemBuilder: (_, index) { - final package = currentPackages[index]; - return PackageListItem( - key: Key(package.packageName), - package: package, - value: - valueList.contains(package.packageName), - isActive: isAccessControl, - onChanged: (value) { - if (value == true) { - valueList.add(package.packageName); - } else { - valueList.remove(package.packageName); - } - final config = - globalState.appController.config; - if (accessControlMode == - AccessControlMode.acceptSelected) { - config.accessControl = - config.accessControl.copyWith( - acceptList: valueList, - ); - } else { - config.accessControl = - config.accessControl.copyWith( - rejectList: valueList, - ); - } - }, - ); - }, - ), + Expanded( + flex: 1, + child: FadeBox( + key: const Key("fade_box"), + child: currentPackages.isEmpty + ? const Center( + child: CircularProgressIndicator(), + ) + : ListView.builder( + itemCount: currentPackages.length, + itemBuilder: (_, index) { + final package = currentPackages[index]; + return PackageListItem( + key: Key(package.packageName), + package: package, + value: + valueList.contains(package.packageName), + isActive: isAccessControl, + onChanged: (value) { + if (value == true) { + valueList.add(package.packageName); + } else { + valueList.remove(package.packageName); + } + final config = + globalState.appController.config; + if (accessControlMode == + AccessControlMode.acceptSelected) { + config.accessControl = + config.accessControl.copyWith( + acceptList: valueList, + ); + } else { + config.accessControl = + config.accessControl.copyWith( + rejectList: valueList, + ); + } + }, + ); + }, + ), + ), ), - ), - ], + ], + ), ), ); }, diff --git a/lib/fragments/profiles/profiles.dart b/lib/fragments/profiles/profiles.dart index 4728f94..7999709 100644 --- a/lib/fragments/profiles/profiles.dart +++ b/lib/fragments/profiles/profiles.dart @@ -76,13 +76,6 @@ class _ProfilesFragmentState extends State { width: 8, ) ]; - commonScaffoldState?.floatingActionButton = FloatingActionButton( - heroTag: null, - onPressed: _handleShowAddExtendPage, - child: const Icon( - Icons.add, - ), - ); }, ); } @@ -113,74 +106,86 @@ class _ProfilesFragmentState extends State { @override Widget build(BuildContext context) { - return Selector( - selector: (_, appState) => appState.currentLabel == 'profiles', - builder: (_, isCurrent, child) { - if (isCurrent) { - _initScaffoldState(); - } - return child!; - }, - child: Selector2( - selector: (_, appState, config) => ProfilesSelectorState( - profiles: config.profiles, - currentProfileId: config.currentProfileId, - viewMode: appState.viewMode, + return FloatLayout( + floatingWidget: FloatWrapper( + child: FloatingActionButton( + heroTag: null, + onPressed: _handleShowAddExtendPage, + child: const Icon( + Icons.add, + ), ), - builder: (context, state, child) { - if (state.profiles.isEmpty) { - return NullStatus( - label: appLocalizations.nullProfileDesc, - ); + ), + child: Selector( + selector: (_, appState) => appState.currentLabel == 'profiles', + builder: (_, isCurrent, child) { + if (isCurrent) { + _initScaffoldState(); } - profileItemKeys = state.profiles - .map((profile) => GlobalObjectKey<_ProfileItemState>(profile.id)) - .toList(); - final columns = _getColumns(state.viewMode); - return Align( - alignment: Alignment.topCenter, - child: NotificationListener( - onNotification: (scrollNotification) { - WidgetsBinding.instance.addPostFrameCallback( - (_) { - hasPadding.value = - scrollNotification.metrics.maxScrollExtent > 0; - }, - ); - return true; - }, - child: ValueListenableBuilder( - valueListenable: hasPadding, - builder: (_, hasPadding, __) { - return SingleChildScrollView( - padding: EdgeInsets.only( - left: 16, - right: 16, - top: 16, - bottom: 16 + (hasPadding ? 56 : 0), - ), - child: Grid( - mainAxisSpacing: 16, - crossAxisSpacing: 16, - crossAxisCount: columns, - children: [ - for (int i = 0; i < state.profiles.length; i++) - GridItem( - child: ProfileItem( - key: profileItemKeys[i], - profile: state.profiles[i], - groupValue: state.currentProfileId, - onChanged: _changeProfile, - ), - ), - ], - ), - ); - }, - ), - ), - ); + return child!; }, + child: Selector2( + selector: (_, appState, config) => ProfilesSelectorState( + profiles: config.profiles, + currentProfileId: config.currentProfileId, + viewMode: appState.viewMode, + ), + builder: (context, state, child) { + if (state.profiles.isEmpty) { + return NullStatus( + label: appLocalizations.nullProfileDesc, + ); + } + profileItemKeys = state.profiles + .map( + (profile) => GlobalObjectKey<_ProfileItemState>(profile.id)) + .toList(); + final columns = _getColumns(state.viewMode); + return Align( + alignment: Alignment.topCenter, + child: NotificationListener( + onNotification: (scrollNotification) { + WidgetsBinding.instance.addPostFrameCallback( + (_) { + hasPadding.value = + scrollNotification.metrics.maxScrollExtent > 0; + }, + ); + return true; + }, + child: ValueListenableBuilder( + valueListenable: hasPadding, + builder: (_, hasPadding, __) { + return SingleChildScrollView( + padding: EdgeInsets.only( + left: 16, + right: 16, + top: 16, + bottom: 16 + (hasPadding ? 56 : 0), + ), + child: Grid( + mainAxisSpacing: 16, + crossAxisSpacing: 16, + crossAxisCount: columns, + children: [ + for (int i = 0; i < state.profiles.length; i++) + GridItem( + child: ProfileItem( + key: profileItemKeys[i], + profile: state.profiles[i], + groupValue: state.currentProfileId, + onChanged: _changeProfile, + ), + ), + ], + ), + ); + }, + ), + ), + ); + }, + ), ), ); } diff --git a/lib/widgets/scaffold.dart b/lib/widgets/scaffold.dart index 6c27233..ae6a0b9 100644 --- a/lib/widgets/scaffold.dart +++ b/lib/widgets/scaffold.dart @@ -49,8 +49,6 @@ class CommonScaffold extends StatefulWidget { class CommonScaffoldState extends State { final ValueNotifier> _actions = ValueNotifier([]); - final ValueNotifier _floatingActionButton = ValueNotifier(null); - final ValueNotifier _loading = ValueNotifier(false); set actions(List actions) { @@ -59,12 +57,6 @@ class CommonScaffoldState extends State { } } - set floatingActionButton(Widget? actions) { - if (_floatingActionButton.value != actions) { - _floatingActionButton.value = actions; - } - } - Future loadingRun( Future Function() futureFunction, { String? title, @@ -89,7 +81,6 @@ class CommonScaffoldState extends State { @override void dispose() { _actions.dispose(); - _floatingActionButton.dispose(); super.dispose(); } @@ -98,7 +89,6 @@ class CommonScaffoldState extends State { super.didUpdateWidget(oldWidget); if (oldWidget.title != widget.title) { _actions.value = []; - _floatingActionButton.value = null; } } diff --git a/pubspec.yaml b/pubspec.yaml index 2f84d32..3697ee3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: fl_clash description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free. publish_to: 'none' -version: 0.8.37+202407141 +version: 0.8.38+202407142 environment: sdk: '>=3.1.0 <4.0.0'