//通过数组中标识队列,判断page的位置(是唯一最顶部,还是唯一最顶部之下的第二个page)
bool isTop(BuildContext context, int num) {
if (_activityStack == null) {
return false;
}
try {
String className = getClassName(context);
int stackLength = _activityStack.length;
int curIndex = (stackLength >= num) ? (stackLength - num) : -1;
String stackClassName = curIndex >= 0 ? _activityStack[curIndex] : null;
return (stackClassName == null) ? false : (stackClassName == className);
} catch (exception) {
return false;
}
}
bool isTopPage(BuildContext context) {
return isTop(context, 1);
}
bool isSecondTop(BuildContext context) {
return isTop(context, 2);
}
}
BaseWidge基类:
import ‘package:flutter/material.dart’;
import ‘navigator_manger.dart’;
abstract class BaseWidget extends StatefulWidget {
@override
BaseWidgetState createState() {
return getState();
}
BaseWidgetState getState();
}
abstract class BaseWidgetState extends State {
String curPage;
String ta