Skip to content

Commit

Permalink
Fix blank screen when middleware is working and no page in the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
SchabanBo committed Dec 22, 2021
1 parent 403188a commit 1c5ba12
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 433 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*.iws
.idea/

.vscode/

# Flutter/Dart/Pub related
**/doc/api/
Expand Down Expand Up @@ -44,4 +43,5 @@ app.*.map.json
example/android/app/debug
example/android/app/profile
example/android/app/release
pubspec.lock
*.lock
.vscode
4 changes: 4 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
example/
Check.ps1
build/
qlevar_router.iml
14 changes: 0 additions & 14 deletions .vscode/launch.json

This file was deleted.

6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## [1.5.9] 21.12.2021

- Fix blank screen when middleware is working and no page in the stack

## [1.5.8] 30.11.2021

- Add `QR.IsSamePath`, `QR.isSameName`
Expand Down
229 changes: 0 additions & 229 deletions example/pubspec.lock

This file was deleted.

30 changes: 22 additions & 8 deletions lib/src/controllers/pages_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import 'middleware_controller.dart';

class PagesController {
final routes = <QRouteInternal>[];
final pages = <QPageInternal>[
QMaterialPageInternal(
child: QR.settings.iniPage, matchKey: QKey('Init Page'))
];
late final pages = <QPageInternal>[_initPage];

bool exist(QRouteInternal route) =>
routes.any((element) => element.key.isSame(route.key));

static const String _initPageKey = 'Init Page';

QMaterialPageInternal get _initPage => QMaterialPageInternal(
child: QR.settings.iniPage, matchKey: QKey(_initPageKey));

Future<void> add(QRouteInternal route) async {
routes.add(route);
await MiddlewareController(route).runOnEnter();
await _notifyObserverOnNavigation(route);
pages.add(PageCreator(route).create());
if (pages.any((element) => element.matchKey.hasName('Init Page'))) {
pages.removeWhere((element) => element.matchKey.hasName('Init Page'));
if (pages.any((element) => element.matchKey.hasName(_initPageKey))) {
pages.removeWhere((element) => element.matchKey.hasName(_initPageKey));
}
}

Expand Down Expand Up @@ -49,6 +51,7 @@ class PagesController {
await _notifyObserverOnPop(route);
routes.removeLast(); // remove from the routes
pages.removeLast(); // reomve from the pages
_checkEmptyStack();
return PopResult.Poped;
}

Expand All @@ -64,13 +67,16 @@ class PagesController {
await _notifyObserverOnPop(route);
routes.removeAt(index); // remove from the routes
pages.removeAt(index); // reomve from the pages
_checkEmptyStack();
return true;
}

Future<PopResult> removeAll() async {
for (var i = 0; i < pages.length; i++) {
for (var i = 0; i < routes.length; i++) {
final result = await removeLast(allowEmptyPages: true);
if (result != PopResult.Poped) return result;
if (result != PopResult.Poped) {
return result;
}
i--;
}
return PopResult.Poped;
Expand All @@ -87,4 +93,12 @@ class PagesController {
await onPop(route.activePath!, route.route);
}
}

/// show init page when a middleware has something to do,
/// so no red screen will be showen
void _checkEmptyStack() {
if (pages.isEmpty) {
pages.add(_initPage);
}
}
}
Loading

0 comments on commit 1c5ba12

Please sign in to comment.