HTTP-клиент к /api/v1 с Sanctum-токеном (хранится в secure storage), модели зеркалят Laravel API Resources. Экраны: логин, список устройств с живым статусом, детальная страница устройства (история телеметрии, turn-on/turn-off/set-level с проверкой capability), списки зон и правил автоматизации (пока только чтение — формы создания/редактирования впереди).
48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../core/auth_service.dart';
|
|
import 'automation_rules_tab.dart';
|
|
import 'devices_tab.dart';
|
|
import 'zones_tab.dart';
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
int _index = 0;
|
|
|
|
static const _titles = ['Устройства', 'Зоны', 'Правила'];
|
|
static const _tabs = [DevicesTab(), ZonesTab(), AutomationRulesTab()];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(_titles[_index]),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.logout),
|
|
tooltip: 'Выйти',
|
|
onPressed: () => context.read<AuthService>().logout(),
|
|
),
|
|
],
|
|
),
|
|
body: IndexedStack(index: _index, children: _tabs),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: _index,
|
|
onDestinationSelected: (index) => setState(() => _index = index),
|
|
destinations: const [
|
|
NavigationDestination(icon: Icon(Icons.devices_other), label: 'Устройства'),
|
|
NavigationDestination(icon: Icon(Icons.room), label: 'Зоны'),
|
|
NavigationDestination(icon: Icon(Icons.rule), label: 'Правила'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|