feat(apps): 重构 UI 架构为 presentation 层并新增 l10n 国际化支持
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../../app/router/app_routes.dart';
|
||||
|
||||
enum HomeReturnAction { pop, goHome, goHomeForDock }
|
||||
|
||||
HomeReturnAction resolveHomeReturnAction({
|
||||
required bool canPop,
|
||||
required bool isAuthEntry,
|
||||
bool forceGoHome = false,
|
||||
}) {
|
||||
if (forceGoHome) {
|
||||
return HomeReturnAction.goHome;
|
||||
}
|
||||
if (isAuthEntry) {
|
||||
return HomeReturnAction.goHome;
|
||||
}
|
||||
if (canPop) {
|
||||
return HomeReturnAction.goHomeForDock;
|
||||
}
|
||||
return HomeReturnAction.goHome;
|
||||
}
|
||||
|
||||
void returnToHomePreserveState(
|
||||
BuildContext context, {
|
||||
bool isAuthEntry = false,
|
||||
bool forceGoHome = false,
|
||||
}) {
|
||||
final action = resolveHomeReturnAction(
|
||||
canPop: context.canPop(),
|
||||
isAuthEntry: isAuthEntry,
|
||||
forceGoHome: forceGoHome,
|
||||
);
|
||||
switch (action) {
|
||||
case HomeReturnAction.pop:
|
||||
context.pop();
|
||||
return;
|
||||
case HomeReturnAction.goHome:
|
||||
context.go(AppRoutes.homeMain);
|
||||
return;
|
||||
case HomeReturnAction.goHomeForDock:
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
return;
|
||||
}
|
||||
context.go(AppRoutes.homeMain);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user