reset ui only on demand

This commit is contained in:
Fabian Freund
2025-10-30 06:59:42 +01:00
parent f0ff1b48a2
commit 6fa8a56643
3 changed files with 31 additions and 22 deletions
@@ -18,21 +18,51 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/widgets.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/core/providers/app_state.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/entities/sheet.dart';
import 'package:weblibre/features/geckoview/features/browser/domain/providers/lifecycle.dart';
part 'bottom_sheet.g.dart';
@Riverpod(keepAlive: true)
class BottomSheetController extends _$BottomSheetController {
DateTime? _pauseTime;
bool _resetDue = false;
@override
Sheet? build() {
ref.listen(browserViewLifecycleProvider, (previous, current) {
switch (current) {
case AppLifecycleState.resumed:
if (_pauseTime != null &&
DateTime.now().difference(_pauseTime!) >
const Duration(minutes: 5)) {
_resetDue = true;
}
_pauseTime = null;
case AppLifecycleState.detached:
case AppLifecycleState.inactive:
case AppLifecycleState.hidden:
case AppLifecycleState.paused:
_pauseTime ??= DateTime.now();
default:
}
});
return null;
}
///We depend on a listener that updates/syncs UI to open the sheet
// ignore: use_setters_to_change_properties api decision
void show(Sheet sheet) {
if (_resetDue) {
ref.read(appStateKeyProvider.notifier).reset();
_resetDue = false;
return;
}
state = sheet;
}
@@ -42,7 +42,7 @@ final class BottomSheetControllerProvider
}
String _$bottomSheetControllerHash() =>
r'54112ccef72ad7777c746b9f2dc02da1e383c127';
r'47234d4bd06187c6f0b85013ffc50ebdd065c90b';
abstract class _$BottomSheetController extends $Notifier<Sheet?> {
Sheet? build();
-21
View File
@@ -23,7 +23,6 @@ import 'package:background_fetch/background_fetch.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart'
show GeckoBrowserService, GeckoLoggingService, LogLevel;
import 'package:home_widget/home_widget.dart';
@@ -48,26 +47,6 @@ class _MainWidget extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final rootKey = ref.watch(appStateKeyProvider);
final pauseTime = useRef<DateTime?>(null);
useOnAppLifecycleStateChange((previous, current) {
switch (current) {
case AppLifecycleState.resumed:
if (pauseTime.value != null &&
DateTime.now().difference(pauseTime.value!) >
const Duration(minutes: 5)) {
//Rebuild widget tree after long time of inactivity
ref.read(appStateKeyProvider.notifier).reset();
logger.i('UI reset');
}
pauseTime.value = null;
case AppLifecycleState.detached:
case AppLifecycleState.inactive:
case AppLifecycleState.hidden:
case AppLifecycleState.paused:
pauseTime.value ??= DateTime.now();
}
});
final themeMode = ref.watch(
generalSettingsWithDefaultsProvider.select((value) => value.themeMode),
);