Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esc_pos_print_plus
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
esc_pos_print_plus
Commits
25ce92eb
Commit
25ce92eb
authored
Jun 12, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Printer class
parent
32edba1d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
12 deletions
+120
-12
esc_pos_printer.dart
lib/esc_pos_printer.dart
+7
-5
printer.dart
lib/src/printer.dart
+106
-0
esc_pos_printer_test.dart
test/esc_pos_printer_test.dart
+7
-7
No files found.
lib/esc_pos_printer.dart
View file @
25ce92eb
/*
* esc_pos_printer
* Created by Andrey U
*
* See LICENSE for distribution and usage details.
*/
library
esc_pos_printer
;
/// A Calculator.
class
Calculator
{
/// Returns [value] plus 1.
int
addOne
(
int
value
)
=>
value
+
1
;
}
export
'./src/printer.dart'
;
lib/src/printer.dart
0 → 100644
View file @
25ce92eb
import
'dart:io'
;
import
'commands.dart'
;
enum
TextAlign
{
left
,
center
,
right
}
/// Abstract printer.
class
Printer
{
Printer
(
this
.
_socket
)
{
reset
();
}
final
Socket
_socket
;
/// Creates a new socket connection to the printer.
///
/// [host] can either be a [String] or an [InternetAddress]. If [host] is a
/// [String], [connect] will perform a [InternetAddress.lookup] and try
/// all returned [InternetAddress]es, until connected. Unless a
/// connection was established, the error from the first failing connection is
/// returned.
///
/// The argument [sourceAddress] can be used to specify the local
/// address to bind when making the connection. `sourceAddress` can either
/// be a `String` or an `InternetAddress`. If a `String` is passed it must
/// hold a numeric IP address.
///
/// The argument [timeout] is used to specify the maximum allowed time to wait
/// for a connection to be established.
static
Future
<
Printer
>
connect
(
host
,
int
port
,
{
sourceAddress
,
Duration
timeout
})
{
return
Socket
.
connect
(
host
,
port
,
sourceAddress:
sourceAddress
,
timeout:
timeout
)
.
then
((
socket
)
{
return
Printer
(
socket
);
});
}
/// Disconnect from the printer
void
disconnect
()
{
_socket
.
destroy
();
}
// void writeAll(Iterable objects, [String separator = '']) {
// socket.writeAll(objects, separator);
// }
// void writeLine([Object obj = '']) {
// socket.writeln(obj);
// }
// void write(Object obj) {
// socket.write(obj);
// }
// TODO charHeight, charWidth range ?
// TODO should be ended by \n
void
println
(
Object
text
,
{
bool
bold
=
false
,
bool
reverse
=
false
,
bool
underline
=
false
,
TextAlign
align
=
TextAlign
.
left
,
int
charHeight
=
-
1
,
int
charWidth
=
-
1
,
int
linesAfter
=
-
1
,
})
{
_socket
.
write
(
bold
?
cBoldOn
:
cBoldOff
);
_socket
.
write
(
reverse
?
cReverseOn
:
cReverseOff
);
_socket
.
write
(
underline
?
cUnderline1dot
:
cUnderlineOff
);
_socket
.
write
(
align
==
TextAlign
.
left
?
cAlignLeft
:
(
align
==
TextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
if
(
charHeight
>
0
&&
charWidth
>
0
)
{
var
n
=
16
*
(
charWidth
-
1
)
+
(
charHeight
-
1
);
_socket
.
writeAll
([
cSizeN
,
n
]);
}
_socket
.
writeln
(
text
);
feed
(
linesAfter
);
// reset all to default
reset
();
}
void
reset
()
{
_socket
.
write
(
cInit
);
}
void
feed
(
int
n
)
{
if
(
n
>=
0
&&
n
<=
255
)
{
_socket
.
writeAll
([
cFeedN
,
n
.
toString
()]);
}
}
void
reverseFeed
(
int
n
)
{
_socket
.
writeAll
([
cReverseFeedN
,
n
.
toString
()]);
}
void
cut
()
{
_socket
.
write
(
'
\n\n\n\n\n
'
);
_socket
.
write
(
cCut
);
}
}
test/esc_pos_printer_test.dart
View file @
25ce92eb
...
...
@@ -3,11 +3,11 @@ import 'package:flutter_test/flutter_test.dart';
import
'package:esc_pos_printer/esc_pos_printer.dart'
;
void
main
(
)
{
test
(
'adds one to input values'
,
()
{
final
calculator
=
Calculator
();
expect
(
calculator
.
addOne
(
2
),
3
);
expect
(
calculator
.
addOne
(-
7
),
-
6
);
expect
(
calculator
.
addOne
(
0
),
1
);
expect
(()
=>
calculator
.
addOne
(
null
),
throwsNoSuchMethodError
);
});
//
test('adds one to input values', () {
//
final calculator = Calculator();
//
expect(calculator.addOne(2), 3);
//
expect(calculator.addOne(-7), -6);
//
expect(calculator.addOne(0), 1);
//
expect(() => calculator.addOne(null), throwsNoSuchMethodError);
//
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment