Skip to content

Commit

Permalink
Fix updating toggling tools not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Dec 31, 2024
1 parent d4e98ef commit 7ba7940
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "dev.linwood.butterfly"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
Expand Down
4 changes: 2 additions & 2 deletions app/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionSha256Sum=7a00d51fb93147819aab76024feece20b6b84e420694101f276be952e08bef03
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 2 additions & 3 deletions app/lib/bloc/document_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,11 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
}).toList())));
final updatedCurrent = event.tools.entries.firstWhereOrNull((element) =>
oldTools[element.key] ==
current.currentIndexCubit.state.handler.data ||
current.currentIndexCubit.state.toggleableHandlers
.containsKey(element.key));
current.currentIndexCubit.state.handler.data);
if (updatedCurrent != null) {
current.currentIndexCubit.updateTool(this, updatedCurrent.value);
}
current.currentIndexCubit.updateTogglingTools(this, event.tools);
final updatedTempCurrent = event.tools.entries.firstWhereOrNull(
(element) =>
oldTools[element.key] ==
Expand Down
36 changes: 36 additions & 0 deletions app/lib/cubits/current_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1191,4 +1191,40 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {
emit(state.copyWith(areaNavigatorExact: value));
void setAreaNavigatorAsk(bool value) =>
emit(state.copyWith(areaNavigatorAsk: value));

void updateTogglingTools(DocumentBloc bloc, Map<int, Tool> tools) {
final blocState = bloc.state;
if (blocState is! DocumentLoadSuccess) return;
final newHandlers = Map<int, Handler<Tool>>.from(state.toggleableHandlers);
final newForegrounds =
Map<int, List<Renderer>>.from(state.toggleableForegrounds);
for (final entry in tools.entries) {
final index = entry.key;
final tool = entry.value;
final old = state.toggleableHandlers[index];
if (old == null) continue;
if (old.data == tool) continue;
old.dispose(bloc);
for (final r in state.toggleableForegrounds[index] ?? []) {
r.dispose();
}
final handler = Handler.fromTool(tool);
final document = blocState.data;
final page = blocState.page;
final info = blocState.info;
final currentArea = blocState.currentArea;
final foregrounds =
handler.createForegrounds(this, document, page, info, currentArea);
if (handler.setupForegrounds) {
Future.wait(foregrounds.map((e) async =>
await e.setup(document, blocState.assetService, page)));
}
newHandlers[index] = handler;
newForegrounds[index] = foregrounds;
}
emit(state.copyWith(
toggleableHandlers: newHandlers,
toggleableForegrounds: newForegrounds,
));
}
}
2 changes: 1 addition & 1 deletion app/lib/setup_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'setup.dart' as general_setup;
import 'embed/action_web.dart' as action;

Future<void> setup() async {
BrowserContextMenu.disableContextMenu();
await BrowserContextMenu.disableContextMenu();
action.setup();
await general_setup.setup();
}
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ packages:
dependency: transitive
description:
name: camera_avfoundation
sha256: "2e4c568f70e406ccb87376bc06b53d2f5bebaab71e2fbcc1a950e31449381bcf"
sha256: c3038e6e72e284b14ad246a419f26908c08f8886d114cb8a2e351988439bfa68
url: "https://pub.dev"
source: hosted
version: "0.9.17+5"
version: "0.9.17+6"
camera_platform_interface:
dependency: transitive
description:
Expand Down

0 comments on commit 7ba7940

Please sign in to comment.