Handle dashboard right layout toggle.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
@@ -15,6 +15,9 @@ import 'package:url_launcher/url_launcher.dart';
|
|||||||
class DashboardController {
|
class DashboardController {
|
||||||
|
|
||||||
final ValueNotifier<bool> canGoBack = ValueNotifier(false);
|
final ValueNotifier<bool> canGoBack = ValueNotifier(false);
|
||||||
|
final ValueNotifier<bool> hasRightLayout = ValueNotifier(false);
|
||||||
|
final ValueNotifier<bool> rightLayoutOpened = ValueNotifier(false);
|
||||||
|
|
||||||
final _DashboardState dashboardState;
|
final _DashboardState dashboardState;
|
||||||
DashboardController(this.dashboardState);
|
DashboardController(this.dashboardState);
|
||||||
|
|
||||||
@@ -30,6 +33,18 @@ class DashboardController {
|
|||||||
canGoBack.value = await canGoBackFuture;
|
canGoBack.value = await canGoBackFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onHasRightLayout(bool _hasRightLayout) {
|
||||||
|
hasRightLayout.value = _hasRightLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
onRightLayoutOpened(bool _rightLayoutOpened) {
|
||||||
|
rightLayoutOpened.value = _rightLayoutOpened;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> toggleRightLayout() async {
|
||||||
|
await dashboardState._toggleRightLayout();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> activateDashboard() async {
|
Future<void> activateDashboard() async {
|
||||||
await dashboardState._activateDashboard();
|
await dashboardState._activateDashboard();
|
||||||
}
|
}
|
||||||
@@ -40,6 +55,8 @@ class DashboardController {
|
|||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
canGoBack.dispose();
|
canGoBack.dispose();
|
||||||
|
hasRightLayout.dispose();
|
||||||
|
rightLayoutOpened.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -187,6 +204,15 @@ class _DashboardState extends TbContextState<Dashboard, _DashboardState> {
|
|||||||
await controller.postWebMessage(message: webMessage, targetOrigin: Uri.parse('*'));
|
await controller.postWebMessage(message: webMessage, targetOrigin: Uri.parse('*'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _toggleRightLayout() async {
|
||||||
|
var controller = await _controller.future;
|
||||||
|
var windowMessage = <String, dynamic>{
|
||||||
|
'type': 'toggleDashboardLayout'
|
||||||
|
};
|
||||||
|
var webMessage = WebMessage(data: jsonEncode(windowMessage));
|
||||||
|
await controller.postWebMessage(message: webMessage, targetOrigin: Uri.parse('*'));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
@@ -217,9 +243,18 @@ class _DashboardState extends TbContextState<Dashboard, _DashboardState> {
|
|||||||
onWebViewCreated: (webViewController) {
|
onWebViewCreated: (webViewController) {
|
||||||
log.debug("onWebViewCreated");
|
log.debug("onWebViewCreated");
|
||||||
webViewController.addJavaScriptHandler(handlerName: "tbMobileDashboardLoadedHandler", callback: (args) async {
|
webViewController.addJavaScriptHandler(handlerName: "tbMobileDashboardLoadedHandler", callback: (args) async {
|
||||||
log.debug("Invoked tbMobileDashboardLoadedHandler");
|
bool hasRightLayout = args[0];
|
||||||
|
bool rightLayoutOpened = args[1];
|
||||||
|
log.debug("Invoked tbMobileDashboardLoadedHandler: hasRightLayout: $hasRightLayout, rightLayoutOpened: $rightLayoutOpened");
|
||||||
|
_dashboardController.onHasRightLayout(hasRightLayout);
|
||||||
|
_dashboardController.onRightLayoutOpened(rightLayoutOpened);
|
||||||
dashboardLoading.value = false;
|
dashboardLoading.value = false;
|
||||||
});
|
});
|
||||||
|
webViewController.addJavaScriptHandler(handlerName: "tbMobileDashboardLayoutHandler", callback: (args) async {
|
||||||
|
bool rightLayoutOpened = args[0];
|
||||||
|
log.debug("Invoked tbMobileDashboardLayoutHandler: rightLayoutOpened: $rightLayoutOpened");
|
||||||
|
_dashboardController.onRightLayoutOpened(rightLayoutOpened);
|
||||||
|
});
|
||||||
webViewController.addJavaScriptHandler(handlerName: "tbMobileDashboardStateNameHandler", callback: (args) async {
|
webViewController.addJavaScriptHandler(handlerName: "tbMobileDashboardStateNameHandler", callback: (args) async {
|
||||||
log.debug("Invoked tbMobileDashboardStateNameHandler: $args");
|
log.debug("Invoked tbMobileDashboardStateNameHandler: $args");
|
||||||
if (args.isNotEmpty && args[0] is String) {
|
if (args.isNotEmpty && args[0] is String) {
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ class MainDashboardPage extends TbContextWidget<MainDashboardPage, _MainDashboar
|
|||||||
class _MainDashboardPageState extends TbContextState<MainDashboardPage, _MainDashboardPageState> {
|
class _MainDashboardPageState extends TbContextState<MainDashboardPage, _MainDashboardPageState> {
|
||||||
|
|
||||||
late ValueNotifier<String> dashboardTitleValue;
|
late ValueNotifier<String> dashboardTitleValue;
|
||||||
|
final ValueNotifier<bool> hasRightLayout = ValueNotifier(false);
|
||||||
|
final ValueNotifier<bool> rightLayoutOpened = ValueNotifier(false);
|
||||||
|
DashboardController? _dashboardController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -104,7 +107,27 @@ class _MainDashboardPageState extends TbContextState<MainDashboardPage, _MainDas
|
|||||||
child: Text(title)
|
child: Text(title)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
|
actions: [
|
||||||
|
ValueListenableBuilder<bool>(
|
||||||
|
valueListenable: hasRightLayout,
|
||||||
|
builder: (context, _hasRightLayout, widget) {
|
||||||
|
if (_hasRightLayout) {
|
||||||
|
return IconButton(
|
||||||
|
onPressed: () => _dashboardController?.toggleRightLayout(),
|
||||||
|
icon: ValueListenableBuilder<bool>(
|
||||||
|
valueListenable: rightLayoutOpened,
|
||||||
|
builder: (context, _rightLayoutOpened, widget) {
|
||||||
|
return Icon(_rightLayoutOpened ? Icons.arrow_back : Icons.menu);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return SizedBox.shrink();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: Dashboard(
|
body: Dashboard(
|
||||||
tbContext,
|
tbContext,
|
||||||
@@ -113,8 +136,15 @@ class _MainDashboardPageState extends TbContextState<MainDashboardPage, _MainDas
|
|||||||
dashboardTitleValue.value = title;
|
dashboardTitleValue.value = title;
|
||||||
},
|
},
|
||||||
controllerCallback: (controller) {
|
controllerCallback: (controller) {
|
||||||
|
_dashboardController = controller;
|
||||||
if (widget._controller != null) {
|
if (widget._controller != null) {
|
||||||
widget._controller!._setDashboardController(controller);
|
widget._controller!._setDashboardController(controller);
|
||||||
|
controller.hasRightLayout.addListener(() {
|
||||||
|
hasRightLayout.value = controller.hasRightLayout.value;
|
||||||
|
});
|
||||||
|
controller.rightLayoutOpened.addListener(() {
|
||||||
|
rightLayoutOpened.value = controller.rightLayoutOpened.value;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user