Skip to content
Snippets Groups Projects
Commit abd93e1e authored by Leon Tappe's avatar Leon Tappe :fire:
Browse files

add printer status to list

parent 2ca7103c
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import 'package:blocs_astaprint/printers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '/environment_config.dart';
import '/models/route_arguments.dart';
class PrinterListPage extends StatefulWidget {
......@@ -21,10 +22,21 @@ class _PrinterListPageState extends State<PrinterListPage> {
final List<String> _places = [];
StreamSubscription<PrintersState> _printerListener;
bool _refreshing = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Druckerliste')),
appBar: AppBar(
title: Text('Druckerliste'),
actions: [
if (EnvironmentConfig.desktop)
IconButton(onPressed: _onRefresh, icon: Icon(Icons.refresh_rounded)),
],
),
floatingActionButton: FloatingActionButton(onPressed: _onCreatePrinter),
body: Center(
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 1024.0),
......@@ -44,25 +56,89 @@ class _PrinterListPageState extends State<PrinterListPage> {
children: _places.map<Widget>((location) {
final locationPrinters =
state.value.where((printer) => printer.location.contains(location));
return Column(children: [
ListTile(
title: Text(location, style: Theme.of(context).textTheme.headline6),
subtitle: Text('${locationPrinters.length} Drucker an diesem Standort'),
contentPadding: const EdgeInsets.only(left: 0.0),
),
...locationPrinters
.map<Widget>(
(e) => ListTile(
leading: Icon(e.coinOperated ? Icons.savings : Icons.print_rounded,
color: Theme.of(context).colorScheme.secondary),
title: Text(e.hostname),
subtitle: Text(e.ip),
onTap: () => Navigator.of(context).pushNamed('/printers/id/',
arguments: PrinterDetailsArguments(e)),
),
)
.toList(),
]);
return Column(
children: [
ListTile(
title: Text(location, style: Theme.of(context).textTheme.headline6),
subtitle: Text('${locationPrinters.length} Drucker an diesem Standort'),
),
GridView.extent(
shrinkWrap: true,
maxCrossAxisExtent: 1024.0 / 3,
childAspectRatio: 35 / 9,
crossAxisSpacing: 8.0,
mainAxisSpacing: 8.0,
children: locationPrinters
.map<Widget>(
(e) => Card(
clipBehavior: Clip.antiAlias,
child: ListTile(
title: Text(e.hostname),
subtitle: Text(e.ip),
onTap: () => Navigator.of(context).pushNamed('/printers/id/',
arguments: PrinterDetailsArguments(e)),
trailing: ConstrainedBox(
constraints:
const BoxConstraints(maxWidth: 128.0, maxHeight: 40.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (e.status?.connection ==
ConnectionStatus.connected &&
(e.status.scan != 0 || e.status.copy != 0))
Tooltip(
message:
'Scanner: ${e.status.scanStatus.join(', ')}\nKopierer: ${e.status.copyStatus.join(', ')}',
child: Icon(
Icons.warning_rounded,
color: (e.status.scan != 0 && e.status.copy != 0)
? Colors.redAccent
: Colors.orangeAccent,
),
),
if (e.status?.connection == ConnectionStatus.connected)
Tooltip(
message:
'Tonerstand:\nCyan: ${e.status?.tonerC ?? 0}%\nMagenta: ${e.status?.tonerM ?? 0}%\nGelb: ${e.status?.tonerY ?? 0}%\nSchwarz: ${e.status?.tonerK ?? 0}%',
child: Icon(Icons.color_lens_rounded,
color: _levelToColor(e.status?.tonerLevel)),
),
if (e.status?.connection == ConnectionStatus.connected)
Tooltip(
message:
'Papier: ${e.status?.totalPaper ?? 0} Seiten',
child: Icon(
Icons.description_rounded,
color: _levelToColor(e.status?.paperLevel),
),
),
Tooltip(
message:
'Verbindungsstatus: ${e.status?.connection == ConnectionStatus.connected ? 'Online' : e.status?.connection == ConnectionStatus.disconnected ? 'Offline' : 'Abfrage läuft'}',
child: Icon(
e.status?.connection ==
ConnectionStatus.disconnected
? Icons.link_off_rounded
: Icons.link_rounded,
color: e.status?.connection ==
ConnectionStatus.connected
? Colors.green
: e.status?.connection ==
ConnectionStatus.disconnected
? Colors.red
: Colors.orangeAccent,
),
),
],
),
),
),
),
)
.toList(),
)
],
);
}).toList(),
),
);
......@@ -78,15 +154,48 @@ class _PrinterListPageState extends State<PrinterListPage> {
);
}
@override
void dispose() {
_printerListener?.cancel();
super.dispose();
}
@override
void initState() {
super.initState();
printersBloc = BlocProvider.of<PrintersBloc>(context);
printersBloc.onRefresh();
_printerListener = printersBloc.stream.listen((PrintersState state) {
if (_refreshing && state.isResult) {
for (var printer in state.value) {
printersBloc.onRefreshPrinterById(printer.deviceId);
}
_refreshing = false;
}
});
}
Color _levelToColor(Level level) {
switch (level) {
case Level.empty:
return Colors.redAccent;
case Level.low:
return Colors.orangeAccent;
case Level.mid:
return Colors.lightGreen;
case Level.full:
return Colors.green;
default:
return grey;
}
}
void _onCreatePrinter() {}
Future<void> _onRefresh() {
_refreshing = true;
printersBloc.onRefresh();
return printersBloc.stream.skip(1).firstWhere((PrintersState state) => state.isResult);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment