diff options
Diffstat (limited to 'lib/ui.dart')
| -rw-r--r-- | lib/ui.dart | 94 |
1 files changed, 87 insertions, 7 deletions
diff --git a/lib/ui.dart b/lib/ui.dart index 3a98be9..66078da 100644 --- a/lib/ui.dart +++ b/lib/ui.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:mqtt_client/mqtt_client.dart'; import 'data.dart'; @@ -90,14 +91,25 @@ class DevicesPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: const Text("Contacts")), - body: const Column( - children: <Widget>[ - Expanded(child: ContactList()), - ], + return const Scaffold( + body: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Padding( + padding: EdgeInsets.all(15.0), + child: Text("Contacts", style: TextStyle(fontSize: 22)), + ), + ContactList(), + Padding( + padding: EdgeInsets.all(15.0), + child: Text("Covers", style: TextStyle(fontSize: 22)), + ), + CoverList(), + ], + ), ), - bottomNavigationBar: const ConnectionStatus(), + bottomNavigationBar: ConnectionStatus(), ); } } @@ -110,6 +122,8 @@ class ContactList extends StatelessWidget { return Consumer<AppState>( builder: (BuildContext context, AppState state, Widget? child) { return ListView.builder( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), itemCount: state.contacts.length, itemBuilder: (BuildContext context, int index) { MapEntry<String, bool> data = state.contacts.entries.elementAt(index); @@ -129,6 +143,72 @@ class ContactList extends StatelessWidget { } } +class CoverList extends StatelessWidget { + const CoverList({super.key}); + + @override + Widget build(BuildContext context) { + return Consumer<AppState>( + builder: (BuildContext context, AppState state, Widget? child) { + return ListView.builder( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: state.covers.length, + itemBuilder: (BuildContext context, int index) { + String cover = state.covers.elementAt(index); + return Column( + children: <Widget>[ + ListTile( + leading: const Icon(Icons.roller_shades), + title: Text(cover), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + IconButton( + icon: const Icon(Icons.arrow_upward), + constraints: const BoxConstraints(), + onPressed: () { + state.publish( + 'cover/$cover/movement', + 'retract', + MqttQos.exactlyOnce + ); + }, + ), + IconButton( + icon: const Icon(Icons.stop), + constraints: const BoxConstraints(), + onPressed: () { + state.publish( + 'cover/$cover/movement', + 'stop', + MqttQos.exactlyOnce + ); + }, + ), + IconButton( + icon: const Icon(Icons.arrow_downward), + constraints: const BoxConstraints(), + onPressed: () { + state.publish( + 'cover/$cover/movement', + 'extend', + MqttQos.exactlyOnce + ); + }, + ), + ], + ), + ), + ], + ); + }, + ); + }, + ); + } +} + class ConnectionStatus extends StatelessWidget { const ConnectionStatus({super.key}); |
