Base pages implementation
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:thingsboard_app/core/entity/entities_widget.dart';
|
||||
import 'package:thingsboard_app/modules/asset/assets_widget.dart';
|
||||
import 'package:thingsboard_app/modules/dashboard/dashboards_widget.dart';
|
||||
import 'package:thingsboard_app/modules/device/devices_widget.dart';
|
||||
import 'package:thingsboard_app/widgets/tb_app_bar.dart';
|
||||
|
||||
import 'package:thingsboard_app/core/context/tb_context.dart';
|
||||
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
import 'package:thingsboard_app/modules/dashboard/dashboard.dart' as dashboardUi;
|
||||
|
||||
class HomePage extends TbPageWidget<HomePage, _HomePageState> {
|
||||
class HomePage extends TbContextWidget<HomePage, _HomePageState> {
|
||||
|
||||
HomePage(TbContext tbContext) : super(tbContext);
|
||||
|
||||
@@ -14,35 +20,85 @@ class HomePage extends TbPageWidget<HomePage, _HomePageState> {
|
||||
|
||||
}
|
||||
|
||||
class _HomePageState extends TbPageState<HomePage, _HomePageState> {
|
||||
class _HomePageState extends TbContextState<HomePage, _HomePageState> {
|
||||
|
||||
final EntitiesWidgetController _entitiesWidgetController = EntitiesWidgetController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_entitiesWidgetController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var homeDashboard = tbContext.homeDashboard;
|
||||
var dashboardState = homeDashboard != null;
|
||||
return Scaffold(
|
||||
appBar: TbAppBar(
|
||||
tbContext,
|
||||
title: const Text('ThingsBoard'),
|
||||
showLoadingIndicator: !dashboardState,
|
||||
elevation: dashboardState ? 0 : null,
|
||||
title: const Text('Home'),
|
||||
),
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return Center(child:
|
||||
Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
child: Text('Devices'),
|
||||
onPressed: () {
|
||||
navigateTo('/devices');
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}),
|
||||
builder: (context) {
|
||||
if (dashboardState) {
|
||||
return _buildDashboardHome(context, homeDashboard!);
|
||||
} else {
|
||||
return _buildDefaultHome(context);
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDashboardHome(BuildContext context, HomeDashboardInfo dashboard) {
|
||||
return dashboardUi.Dashboard(tbContext, dashboardId: dashboard.dashboardId!.id!,
|
||||
fullscreen: false, home: true, hideToolbar: dashboard.hideDashboardToolbar);
|
||||
}
|
||||
|
||||
Widget _buildDefaultHome(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => _entitiesWidgetController.refresh(),
|
||||
child: ListView(
|
||||
children: _buildUserHome(context)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildUserHome(BuildContext context) {
|
||||
if (tbClient.isSystemAdmin()) {
|
||||
return _buildSysAdminHome(context);
|
||||
} else if (tbClient.isTenantAdmin()) {
|
||||
return _buildTenantAdminHome(context);
|
||||
} else {
|
||||
return _buildCustomerUserHome(context);
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> _buildSysAdminHome(BuildContext context) {
|
||||
return [Container(child: Text('TODO: Implement'))];
|
||||
}
|
||||
|
||||
List<Widget> _buildTenantAdminHome(BuildContext context) {
|
||||
return [
|
||||
AssetsWidget(tbContext, controller: _entitiesWidgetController),
|
||||
DevicesWidget(tbContext, controller: _entitiesWidgetController),
|
||||
DashboardsWidget(tbContext, controller: _entitiesWidgetController)
|
||||
];
|
||||
}
|
||||
|
||||
List<Widget> _buildCustomerUserHome(BuildContext context) {
|
||||
return [
|
||||
AssetsWidget(tbContext, controller: _entitiesWidgetController),
|
||||
DevicesWidget(tbContext, controller: _entitiesWidgetController),
|
||||
DashboardsWidget(tbContext, controller: _entitiesWidgetController)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
20
lib/modules/home/home_routes.dart
Normal file
20
lib/modules/home/home_routes.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:thingsboard_app/config/routes/router.dart';
|
||||
import 'package:thingsboard_app/core/context/tb_context.dart';
|
||||
import 'package:thingsboard_app/modules/main/main_page.dart';
|
||||
|
||||
class HomeRoutes extends TbRoutes {
|
||||
|
||||
late var homeHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
|
||||
return MainPage(tbContext, path: '/home');
|
||||
});
|
||||
|
||||
HomeRoutes(TbContext tbContext) : super(tbContext);
|
||||
|
||||
@override
|
||||
void doRegisterRoutes(router) {
|
||||
router.define("/home", handler: homeHandler);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user