Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show black screen when back from main screen #185

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/extension/navigator_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Fries_I23
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

extension NavigatorExtension on NavigatorState {
@optionalTypeArgs
Future<void> popOrExit<T extends Object?>([T? result]) async {
if (!canPop()) return SystemNavigator.pop();
return pop(result);
}
}
5 changes: 4 additions & 1 deletion lib/view/page_habits_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import '../component/helper.dart';
import '../component/widget.dart';
import '../extension/async_extensions.dart';
import '../extension/color_extensions.dart';
import '../extension/navigator_extensions.dart';
import '../l10n/localizations.dart';
import '../logging/helper.dart';
import '../model/habit_daily_record_form.dart';
Expand Down Expand Up @@ -1104,7 +1105,9 @@ class _HabitsDisplayView extends State<HabitsDisplayView>
onPopInvoked: (didPop) async {
if (didPop) return;
final canPopNow = await onWillPop();
if (mounted && canPopNow) Navigator.pop(this.context);
if (mounted && canPopNow) {
await Navigator.of(this.context).popOrExit();
}
},
child: Scaffold(
resizeToAvoidBottomInset: false,
Expand Down
5 changes: 4 additions & 1 deletion lib/view/page_habits_status_changer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import '../common/utils.dart';
import '../component/helper.dart';
import '../component/widget.dart';
import '../extension/context_extensions.dart';
import '../extension/navigator_extensions.dart';
import '../logging/helper.dart';
import '../model/custom_date_format.dart';
import '../model/habit_date.dart';
Expand Down Expand Up @@ -177,7 +178,9 @@ class _HabitsStatusChangerView extends State<HabitsStatusChangerView> {
: true;
if (!mounted) return;

if (result) dismissAllToolTips().then((_) => Navigator.pop(context));
if (result) {
dismissAllToolTips().then((_) => Navigator.of(context).popOrExit());
}
}

Widget _buildDebugInfo(BuildContext context) =>
Expand Down