4 changed files with 65 additions and 42 deletions
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
// modules/tab_content_registry.dart |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:win_text_editor/framework/models/tab_model.dart'; |
||||
import 'package:win_text_editor/shared/base/base_content_controller.dart'; |
||||
import 'package:win_text_editor/modules/content_search/controllers/content_search_controller.dart'; |
||||
import 'package:win_text_editor/modules/template_parser/controllers/template_parser_controller.dart'; |
||||
import 'package:win_text_editor/modules/content_search/widgets/content_search_view.dart'; |
||||
import 'package:win_text_editor/modules/template_parser/widgets/template_parser_view.dart'; |
||||
|
||||
class RouterKey { |
||||
static const String contentSearch = 'content_search'; |
||||
static const String templateParser = 'template_parser'; |
||||
static const String textEditor = 'text_editor'; |
||||
} |
||||
|
||||
class ModuleRouter { |
||||
//映射控制器 |
||||
static final Map<String, ContentControllerCreator> _controllerCreators = { |
||||
RouterKey.contentSearch: (tab) => ContentSearchController(), |
||||
RouterKey.templateParser: (tab) => TemplateParserController(), |
||||
}; |
||||
|
||||
// 映射UI组件 |
||||
static final Map<String, ContentWidgetBuilder> _widgetBuilders = { |
||||
RouterKey.contentSearch: (tab, controller) => ContentSearchView(tabId: tab.id), |
||||
RouterKey.templateParser: (tab, controller) => TemplateParserView(tabId: tab.id), |
||||
}; |
||||
|
||||
static BaseContentController? createControllerForTab(AppTab tab) { |
||||
final creator = _controllerCreators[tab.type]; |
||||
return creator != null ? creator(tab) : null; |
||||
} |
||||
|
||||
static Widget buildWidgetForTab(AppTab tab, ChangeNotifier? controller) { |
||||
final builder = _widgetBuilders[tab.type] ?? _widgetBuilders['default']; |
||||
return builder!(tab, controller); |
||||
} |
||||
|
||||
static void registerControllerCreator(String type, ContentControllerCreator creator) { |
||||
_controllerCreators[type] = creator; |
||||
} |
||||
|
||||
static void registerWidgetBuilder(String type, ContentWidgetBuilder builder) { |
||||
_widgetBuilders[type] = builder; |
||||
} |
||||
} |
||||
|
||||
typedef ContentControllerCreator = BaseContentController Function(AppTab tab); |
||||
typedef ContentWidgetBuilder = Widget Function(AppTab tab, ChangeNotifier? controller); |
Loading…
Reference in new issue