Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
AStAPrint Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AStA
AStAPrint Admin
Commits
abd93e1e
Commit
abd93e1e
authored
2 years ago
by
Leon Tappe
Browse files
Options
Downloads
Patches
Plain Diff
add printer status to list
parent
2ca7103c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/pages/printer_list/printer_list_page.dart
+129
-20
129 additions, 20 deletions
lib/pages/printer_list/printer_list_page.dart
with
129 additions
and
20 deletions
lib/pages/printer_list/printer_list_page.dart
+
129
−
20
View file @
abd93e1e
...
...
@@ -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(', ')}
\n
Kopierer:
${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:
\n
Cyan:
${e.status?.tonerC ?? 0}
%
\n
Magenta:
${e.status?.tonerM ?? 0}
%
\n
Gelb:
${e.status?.tonerY ?? 0}
%
\n
Schwarz:
${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
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment