|
@@ -9,7 +9,7 @@ import 'package:app_flowy/workspace/presentation/widgets/prelude.dart';
|
|
typedef NavigationCallback = void Function(String id);
|
|
typedef NavigationCallback = void Function(String id);
|
|
|
|
|
|
abstract class NavigationItem {
|
|
abstract class NavigationItem {
|
|
- Widget get titleWidget;
|
|
|
|
|
|
+ Widget get naviTitle;
|
|
String get identifier;
|
|
String get identifier;
|
|
|
|
|
|
NavigationCallback get action => (id) {
|
|
NavigationCallback get action => (id) {
|
|
@@ -25,30 +25,44 @@ enum HomeStackType {
|
|
|
|
|
|
List<HomeStackType> pages = HomeStackType.values.toList();
|
|
List<HomeStackType> pages = HomeStackType.values.toList();
|
|
|
|
|
|
-abstract class HomeStackContext extends Equatable with NavigationItem {
|
|
|
|
|
|
+abstract class HomeStackContext<T> with NavigationItem {
|
|
List<NavigationItem> get navigationItems;
|
|
List<NavigationItem> get navigationItems;
|
|
|
|
|
|
@override
|
|
@override
|
|
- Widget get titleWidget;
|
|
|
|
|
|
+ Widget get naviTitle;
|
|
|
|
|
|
@override
|
|
@override
|
|
String get identifier;
|
|
String get identifier;
|
|
|
|
|
|
|
|
+ ValueNotifier<T> get isUpdated;
|
|
|
|
+
|
|
HomeStackType get type;
|
|
HomeStackType get type;
|
|
|
|
|
|
- Widget render();
|
|
|
|
|
|
+ Widget buildWidget();
|
|
|
|
+
|
|
|
|
+ void dispose();
|
|
}
|
|
}
|
|
|
|
|
|
class HomeStackNotifier extends ChangeNotifier {
|
|
class HomeStackNotifier extends ChangeNotifier {
|
|
- HomeStackContext inner;
|
|
|
|
- HomeStackNotifier({HomeStackContext? context}) : inner = context ?? BlankStackContext();
|
|
|
|
|
|
+ HomeStackContext stackContext;
|
|
|
|
+ Widget get titleWidget => stackContext.naviTitle;
|
|
|
|
+
|
|
|
|
+ HomeStackNotifier({HomeStackContext? context}) : stackContext = context ?? BlankStackContext();
|
|
|
|
|
|
set context(HomeStackContext context) {
|
|
set context(HomeStackContext context) {
|
|
- inner = context;
|
|
|
|
|
|
+ notifyChange() {
|
|
|
|
+ notifyListeners();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ stackContext.isUpdated.removeListener(notifyChange);
|
|
|
|
+ stackContext.dispose();
|
|
|
|
+
|
|
|
|
+ stackContext = context;
|
|
|
|
+ stackContext.isUpdated.addListener(notifyChange);
|
|
notifyListeners();
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
|
|
- HomeStackContext get context => inner;
|
|
|
|
|
|
+ HomeStackContext get context => stackContext;
|
|
}
|
|
}
|
|
|
|
|
|
// HomeStack is initialized as singleton to controll the page stack.
|
|
// HomeStack is initialized as singleton to controll the page stack.
|
|
@@ -57,7 +71,7 @@ class HomeStackManager {
|
|
HomeStackManager();
|
|
HomeStackManager();
|
|
|
|
|
|
Widget title() {
|
|
Widget title() {
|
|
- return _notifier.context.titleWidget;
|
|
|
|
|
|
+ return _notifier.context.naviTitle;
|
|
}
|
|
}
|
|
|
|
|
|
void setStack(HomeStackContext context) {
|
|
void setStack(HomeStackContext context) {
|
|
@@ -71,9 +85,12 @@ class HomeStackManager {
|
|
providers: [
|
|
providers: [
|
|
ChangeNotifierProvider.value(value: _notifier),
|
|
ChangeNotifierProvider.value(value: _notifier),
|
|
],
|
|
],
|
|
- child: Consumer(builder: (ctx, HomeStackNotifier notifier, child) {
|
|
|
|
- return HomeTopBar(view: notifier.context);
|
|
|
|
- }),
|
|
|
|
|
|
+ child: Selector<HomeStackNotifier, Widget>(
|
|
|
|
+ selector: (context, notifier) => notifier.titleWidget,
|
|
|
|
+ builder: (context, widget, child) {
|
|
|
|
+ return const HomeTopBar();
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -87,7 +104,7 @@ class HomeStackManager {
|
|
index: pages.indexOf(notifier.context.type),
|
|
index: pages.indexOf(notifier.context.type),
|
|
children: HomeStackType.values.map((viewType) {
|
|
children: HomeStackType.values.map((viewType) {
|
|
if (viewType == notifier.context.type) {
|
|
if (viewType == notifier.context.type) {
|
|
- return notifier.context.render();
|
|
|
|
|
|
+ return notifier.context.buildWidget();
|
|
} else {
|
|
} else {
|
|
return const BlankStackPage();
|
|
return const BlankStackPage();
|
|
}
|
|
}
|