fix key usage issue after long inactivity

This commit is contained in:
Fabian Freund
2025-09-15 06:04:45 +02:00
parent 31621f580f
commit 2b667e3f11
@@ -57,8 +57,6 @@ class BrowserScreen extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final scaffoldKey = useMemoized(() => GlobalKey<ScaffoldState>());
final eventService = ref.watch(eventServiceProvider); final eventService = ref.watch(eventServiceProvider);
final sheetDisplayed = ref.watch( final sheetDisplayed = ref.watch(
@@ -106,56 +104,6 @@ class BrowserScreen extends HookConsumerWidget {
); );
final sheetController = useRef<PersistentBottomSheetController?>(null); final sheetController = useRef<PersistentBottomSheetController?>(null);
ref.listen(bottomSheetControllerProvider, (previous, next) {
final state = scaffoldKey.currentState;
if (state != null) {
if (sheetController.value != null) {
sheetController.value!.close();
sheetController.value = null;
}
if (next != null) {
final relativeSafeArea = MediaQuery.of(context).relativeSafeArea();
sheetController.value = state.showBottomSheet((context) {
bool dismissOnThreshold(
DraggableScrollableNotification notification,
) {
if (notification.extent <= 0.1) {
ref.read(bottomSheetControllerProvider.notifier).dismiss();
return true;
} else {
ref
.read(bottomSheetExtendProvider.notifier)
.add(notification.extent);
}
return false;
}
final sheet = switch (next) {
ViewTabsSheet() =>
NotificationListener<DraggableScrollableNotification>(
key: ValueKey(next),
onNotification: dismissOnThreshold,
child: _ViewTabsSheet(maxChildSize: relativeSafeArea),
),
final EditUrlSheet parameter =>
NotificationListener<DraggableScrollableNotification>(
key: ValueKey(parameter),
onNotification: dismissOnThreshold,
child: _ViewUrlSheet(
initialTabState: parameter.tabState,
maxChildSize: relativeSafeArea,
),
),
};
return sheet;
});
}
}
});
return PopScope( return PopScope(
//We need this for BackButtonListener to work downstream //We need this for BackButtonListener to work downstream
@@ -164,7 +112,6 @@ class BrowserScreen extends HookConsumerWidget {
child: Theme( child: Theme(
data: themeData, data: themeData,
child: Scaffold( child: Scaffold(
key: scaffoldKey,
extendBodyBehindAppBar: tabInFullScreen, extendBodyBehindAppBar: tabInFullScreen,
bottomNavigationBar: HookConsumer( bottomNavigationBar: HookConsumer(
builder: (context, ref, child) { builder: (context, ref, child) {
@@ -265,7 +212,8 @@ class BrowserScreen extends HookConsumerWidget {
); );
}, },
), ),
body: DragTarget<TabDragData>( body: Consumer(
child: DragTarget<TabDragData>(
onMove: (details) { onMove: (details) {
ref ref
.read(willAcceptDropProvider.notifier) .read(willAcceptDropProvider.notifier)
@@ -323,7 +271,9 @@ class BrowserScreen extends HookConsumerWidget {
} }
if (overlayBuilder != null) { if (overlayBuilder != null) {
ref.read(overlayControllerProvider.notifier).dismiss(); ref
.read(overlayControllerProvider.notifier)
.dismiss();
return true; return true;
} }
@@ -422,6 +372,63 @@ class BrowserScreen extends HookConsumerWidget {
); );
}, },
), ),
builder: (context, ref, child) {
ref.listen(bottomSheetControllerProvider, (previous, next) {
if (sheetController.value != null) {
sheetController.value!.close();
sheetController.value = null;
}
if (next != null) {
final relativeSafeArea = MediaQuery.of(
context,
).relativeSafeArea();
sheetController.value = Scaffold.of(context).showBottomSheet((
context,
) {
bool dismissOnThreshold(
DraggableScrollableNotification notification,
) {
if (notification.extent <= 0.1) {
ref
.read(bottomSheetControllerProvider.notifier)
.dismiss();
return true;
} else {
ref
.read(bottomSheetExtendProvider.notifier)
.add(notification.extent);
}
return false;
}
final sheet = switch (next) {
ViewTabsSheet() =>
NotificationListener<DraggableScrollableNotification>(
key: ValueKey(next),
onNotification: dismissOnThreshold,
child: _ViewTabsSheet(maxChildSize: relativeSafeArea),
),
final EditUrlSheet parameter =>
NotificationListener<DraggableScrollableNotification>(
key: ValueKey(parameter),
onNotification: dismissOnThreshold,
child: _ViewUrlSheet(
initialTabState: parameter.tabState,
maxChildSize: relativeSafeArea,
),
),
};
return sheet;
});
}
});
return child!;
},
),
floatingActionButton: ReaderAppearanceButton(), floatingActionButton: ReaderAppearanceButton(),
), ),
), ),